我非常熟悉Autofac,我非常喜欢Autofac的一个功能是模块的注册.有人知道我能用Unity做什么吗?我很难找到要在Google中使用哪些术语来提出统一性等价物,如果有的话.
public class Global : HttpApplication,IContainerProviderAccessor { private static IContainerProvider _containerProvider; protected void Application_Start(object sender,EventArgs e) { var builder = new ContainerBuilder(); builder.RegisterModule(new MyWebModule()); _containerProvider = new ContainerProvider(builder.Build()); } [...] public IContainerProvider ContainerProvider { get { return _containerProvider; } } } public class MyWebModule: Module { protected override void Load(ContainerBuilder builder) { builder.RegisterModule(new ApplicationModule()); builder.RegisterModule(new DomainModule()); } } public class ApplicationModule: Module { protected override void Load(ContainerBuilder builder) { builder.Register(c => new ProductPresenter(c.Resolve<IProductView>())) .As<ProductPresenter>() .ContainerScoped(); } }
解决方法
你不行只需使用Autofac或Windsor.你会发现在Unity里有很多的缺失,有什么工作在意想不到的方式.这不值得你的时间.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。