public void Configure(IIoCManager manager) { //设置测试环境IoC设置 返回一个新的IoC容器 manager.ConfigureDefaultContianer( () => { //新的IoC容器 var c = new UnityIoCContainer(new IoCContext(manager,new ExpandoObject())); //注册一个自定义的connection string c.GetContainerCore<IUnityContainer>() .RegisterType<MappedDbContext<object>>(//要替换其中参数所以调用了Unity底层 new InjectionConstructor(new InjectionParameter(typeof(string), _connectionString))); //对于这个实现,设定一个扫描程序集 运行其中所有的模型设置: c.RegisterInstance<System.Reflection.Assembly>(MappedDbContext<object>.RegisterModelConfiguresName, typeof(GroupConfiguration).Assembly); //默认DbContext实现注册 c.RegisterType<DbContext, MappedDbContext<object>>(); //默认UOW实现注册 c.RegisterType<IUnitOfWork, EFUnitOfWork>(); //注册业务组件实现 c.RegisterType<IUserService, UserService>(); c.RegisterType<IGroupService, GroupService>(); //注册Logger c.RegisterType<IStandardLogger, StandardLogger>(); c.RegisterInstance<IChannel<StandardLevels>>("Debug",new DEAD.Logging.Log4net.Log4netStandardChannel("Debug",StandardLevels.Debug, log4net.LogManager.GetLogger("Debug"))); return c; }); }
public void Configure(IIoCManager manager) { //设置测试环境IoC设置 返回一个新的IoC容器 manager.ConfigureDefaultContianer( () => { //新的IoC容器 var c = new UnityIoCContainer(new IoCContext(manager, new ExpandoObject())); //注册一个自定义的connection string c.GetContainerCore <IUnityContainer>() .RegisterType <MappedDbContext <object> >( //要替换其中参数所以调用了Unity底层 new InjectionConstructor(new InjectionParameter(typeof(string), _connectionString))); //对于这个实现,设定一个扫描程序集 运行其中所有的模型设置: c.RegisterInstance <System.Reflection.Assembly>(MappedDbContext <object> .RegisterModelConfiguresName, typeof(GroupConfiguration).Assembly); //默认DbContext实现注册 c.RegisterType <DbContext, MappedDbContext <object> >(); //默认UOW实现注册 c.RegisterType <IUnitOfWork, EFUnitOfWork>(); //注册业务组件实现 c.RegisterType <IUserService, UserService>(); c.RegisterType <IGroupService, GroupService>(); //注册Logger c.RegisterType <IStandardLogger, StandardLogger>(); c.RegisterInstance <IChannel <StandardLevels> >("Debug", new DEAD.Logging.Log4net.Log4netStandardChannel("Debug", StandardLevels.Debug, log4net.LogManager.GetLogger("Debug"))); return(c); }); }
public static IoCContainer CreateContainer(IoCContainerType containerType) { IoCContainer container; switch (containerType) { case IoCContainerType.Autofac: container = new AutofacIoCContainer(); break; case IoCContainerType.CastleWindsor: container = new CastleWindsorIoCContainer(); break; case IoCContainerType.Unity: container = new UnityIoCContainer(); break; default: throw new Exception("Incorrect Inversion Of Control Container Type"); } return container; }