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第三方库


热门话题
virtualbox无法从java移动共享文件夹中的文件   java如何连接Android 4.3.5(GA)的apache HttpClient库?   片段中的java Recyclerview未立即显示警报对话框结果   javac(n,r)计算器程序不工作   java使用BooleanQuery还是编写更多索引?   如何在java中设置y/n循环?   java不兼容的通用通配符捕获   java如何在安卓xml中编写数据绑定时的三元操作条件   java如何使用FileDialog?   java如何创建单元测试来检测是否有人使用错误的编码编辑了文件?   java如何从唯一的字符串生成唯一的int?   java gradletomcatplugin:log4j:WARN找不到记录器的附加程序   java我的动态编程解决方案(Kefa和第一步)在codeforces中有什么问题?   java每天更新两个数据库,使它们都包含相同的有效数据集   java如何检查给定的时间是否在时间限制之间   java在单个json POST上保存父级和子级   java如何获取Solr字段类型