码迷,mamicode.com
首页 > 其他好文 > 详细

Autofac 属性注入

时间:2018-10-02 13:51:19      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:red   container   tps   contain   mvc   放弃   通过   reg   平台   

只有对象是通过注入方式获取时,它的属性对象才可以被自动注入

 

例如:

 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

 


 

Autofac 属性注入

标签:red   container   tps   contain   mvc   放弃   通过   reg   平台   

原文地址:https://www.cnblogs.com/voiceangel/p/9736324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!