Pythonic-spring

Latest version: v0.0.1.5

Safety actively analyzes 681812 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

0.0.1.2

两个装饰器:

- Service:装饰class,根据spring.json自动生成bean,并通过BeanFactory注册
- Autowired:装饰__init__方法,根据bean_modules和bean_ids自动注入注册的bean到类中。

SpringApplication:构建即使用,支持输入通配扫描代码并延迟import, 提供了bean_id和type两种找bean的方式

spring.json:扫描并反序列,供BeanFactory读取

使用方法

安装pip包

pip install pythonic-spring

创建实例

from pythonicspring import SpringApplication
app = SpringApplication()

声明需要bean化的类,使用类装饰器:Service

声明类内需要引用的bean,在__init__方法上使用装饰器:Autowired

from pythonicspring import Service
from pythonicspring import Autowired
Service
class ClassA:

class_b: ClassB = None
class_c: ClassC = None

Autowired(bean_modules={"class_b": ClassB}, bean_ids={"class_c": "ClassCCC"})
def __init__(self):
pass

def foo(self):
result = class_b.spam()
pass

一个例子:

test/playground.py

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.