HttpConfiguration config = GlobalConfiguration.Configuration
builder.RegisterType<HomeController>()
builder.RegisterApiControllers(Assembly.GetExecutingAssembly())
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).As<IPerson>() .InstancePerApiRequest()
var container = builder.Build()
config.DependencyResolver = new AutofacWebApiDependencyResolver(container)
DependencyResolver.SetResolver(new AutofacDependencyResolver(container))
依赖注入依靠的是向注入服务(对于你来说就是Autofac)提前注册类型。所以如果你要注入一个Func,那就要先注册:builder.Register<Func<...>>(typeof(该代理的实例))
总的来说,和注册接口也没什么区别。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)