Files
Yi.Framework/Yi.Doc.Md/02.框架功能模块/04.属性注入.md
2023-12-16 15:26:27 +08:00

15 lines
786 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 简介
默认推荐的构造函数注入,依赖关系会非常明确
但是,会给程序带来大量的重复依赖注入代码,构造函数会非常的冗余
所以在Abp的中内置了属性注入方式
> 不是开玩笑,万不得已,最好别用。我也被坑过很多次,带来的弊端也非常明显,难以调试,且依赖关系不清晰,生命周期也是在构造函数之后
## 使用方式
使用极为简单:
``` cs
public IArticleRepository ArticleRepository { get; set; }
```
在具备get与set方法的属性上打上Autowired特性即可在该类被注入时候该属性会在容器中寻找并且赋值
我们的实现方式是通过AutoFac的模块你需要在启动的Host中添加autofac的属性注入模块