在Unity中,我能够轻松地将通用接口映射到通用实现,因此对于所有的ISomething,我都可以将SomethingImpl映射为单一注册。如何注册通用接口到通用实现
var container = new UnityContainer();
//Map all generic repositories to their concrete generic implementations.
container.RegisterType(
typeof(IRepository<,>),
typeof(Repository<,>)
);
var EmployeeRepository = container.Resolve<IRepository<Employee, int>>();
Munq会如何实现?
你确实可以gister使用Unity开放泛型,但使用了不同的语法,如我的答案所示。你没有语法糖,但你可以做到。 – JotaBe 2016-06-28 08:43:26