我想用.net核心(RC2)框架创建一个洋葱类型的架构。
我创建了一个控制台应用程序(.NET Core)和5个类库(.NET Core)
Example.Logic引用了Example.Logic.Interfaces,Example.Repository.Interfaces和Example.Model
Example.Repository引用了Example.Repository.Interfaces
对于依赖注入,我依赖于Autofac(Autofac.Extensions.DependencyInjection)。在Example.Logic和Example.Repository中,我有自动命令模块,用于注册接口和具体类。
public class Configuration : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<EmployerLogic>().As<IEmployerLogic>();
}
}
我的控制台看起来像这样
public class Program
{
public static void Main()
{
var builder = new ContainerBuilder();
builder.RegisterModule<Logic.Configuration>();
var container = builder.Build();
GetEmployers(container);
}
private static void GetEmployers(IContainer container)
{
var employerLogic = container.Resolve<IEmployerLogic>();
employerLogic.GetEmployers();
var repository = container.Resolve<Repository.Interfaces.IRepository<string>>();
}
}
因为我引用了Example.Logic,所以我现在也可以访问Example.Repository.IRepository。请参阅 var repository = container.Resolve ...
所以我的问题是: