python的服务定位器。

luogo的Python项目详细描述


loogo是python3的基本服务定位器。我在java中进行了大量的依赖注入和服务定位工作,并认为用我当前选择的语言从头开始构建一些东西会很有意思。

为什么叫luogo?我现在并没有充满有趣/聪明的想法;但是,我一直在看这部意大利犯罪剧,它激发了我学习意大利语的灵感……

你现在可能已经猜到“loogo”是意大利语的locationplace

安装

pip install luogo

用法

可以从在服务文件中定义服务开始(名称中必须包含“service”)。 服务用service装饰符表示。

# world_servce.pyfromluogoimportService@ServiceclassHelloWorldService:defgreeting(self):return"Hello World!"

然后,您的服务客户机或实现可以位于任何文件或模块中。

# client.pyfromluogoimportLocator,Implementation@ImplementationclassHelloWorldServiceClient:defgreeting(self):service=Locator.get_service("HelloWorldService")returnservice.greeting()
print(HelloWorldServiceClient().greeting())# Hello World!

您还可以将功能标记为服务:

# world_service.pyfromluogoimportService@Servicedefhello_world_service:return"Hello World!"
# client.pyfromluogoimportLocator,Implementation@Implementationdefhello_world_service_client:returnLocator.get_service("hello_world_service")
print(hello_world_service_client())# Hello World!

注释

  • I finally made it a thing to start using python3 so this probably isn’t python2 compatible (might have used a python3 lib somewhere). I might work on it though.
  • Services need to be a file that features the word service somewhere in the file name; however, implementations can be anywhere.
  • Locator depends on a case insensitive string representation of the service name; however, it’s easy to get that if you don’t always feel like typing it out.

为我的目的工作,希望它能对其他人有用!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何为本地和Jenkins执行实现Java配置?   多日志文件创建的java log4j滚动追加器问题   安卓 java替换列表内容或替换引用值本身   java JOptionPane如何不尊重同步?   java Spring状态机访问eventNotAccepted侦听器中的StateContext   Java中的快速排序算法程序   java私有静态最终双精度为0   java中ByteBuffer的clear()方法   同步Java可重入锁的正确锁定/解锁用法   java拦截Couchbaselite中的CRUD操作   用于搜索广告的active directory Java程序   java为什么netty的handler成员变量在使用新handler()处理请求时不重置   java Mockito验证(…)fails“实际上,与此模拟没有任何交互。”按顺序在多个测试运行中   java为什么我的Alarmmanager在终止我的应用程序后不工作?   java如何正确排序groovy列表   一段时间后,java OAuth“401:无效凭据”   使用jtable和数据库在javaswing中进行分页   java如何在Android中将ASCII字符转换为字符串?   java如何运行。来自Javascript的jar方法   java Apache vfs:获取目录的最新更改文件(sftp)