Autofac 屬性注入


只有對象是通過注入方式獲取時,它的屬性對象才可以被自動注入

 

例如:

 Class Mother{

   public Son _son {get;set}

}

 

public IServiceProvider ConfigureServices(IServiceCollection services){

ContainerBuilder builder = new ContainerBuilder();
builder.Populate(services);

builder.RegisterType<Son>();

builder.RegisterType<Mother>().PropertiesAutowired();

 

只有Mother通過注入方式獲取(最初的注入只能是構造函數),_son 屬性才能注入

 網上找到有用 builder.RegisterContoller()的,需要引入 Autofac Asp.net mvc5 ,但這個組件是asp.net 4.6的,不是core,所以,不能跨平台。

所以直接放棄了。

 

參考:

https://www.cnblogs.com/elvinle/p/6232365.html

 


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM