加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 我可以在Unity中的模块中注册我的类型,就像在Autofac中一

发布时间:2020-12-15 03:51:35 所属栏目:百科 来源:网络整理
导读:我非常熟悉Autofac,我非常喜欢Autofac的一个功能是模块的注册.有人知道我能用Unity做什么吗?我很难找到要在Google中使用哪些术语来提出统一性等价物,如果有的话. public class Global : HttpApplication,IContainerProviderAccessor{ private static IConta
我非常熟悉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里有很多的缺失,有什么工作在意想不到的方式.这不值得你的时间.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读