Autofac寄存器组合件类型 [英] Autofac register assembly types

查看:78
本文介绍了Autofac寄存器组合件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Castle中,我经常执行以下操作以注册来自不同程序集的类型:

In Castle, I used to do the following to register types from a different assembly:

Classes.FromAssemblyNamed("MyServer.DAL")
       .Where(type => type.Name.EndsWith("Repository"))
       .WithServiceAllInterfaces()
       .LifestylePerWebRequest(),

在Autofac中,我将上面的代码更改为此:

In Autofac, I change the above code to this:

builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
       .Where(t => t.Name.EndsWith("Repository"))
       .InstancePerRequest();

对吗?

推荐答案

这是正确的方法:

builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
       .Where(t => t.Name.EndsWith("Repository"))
       .AsImplementedInterfaces()
       .InstancePerRequest();

这篇关于Autofac寄存器组合件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆