コード例 #1
0
        protected void regedit()
        {
            Log4NetManager.Initialize("log4net.config");
            LoggerManager.Logger.Info("应用程序启动");

            this.unityContainer = new UnityContainer();
            IoC.Initialize(
                (x, y) => this.unityContainer.RegisterType(x, y),
                (x, y) => this.unityContainer.RegisterInstance(x, y),
                (x) => { return unityContainer.Resolve(x); },
                (x) => { return unityContainer.ResolveAll(x); });

            // Context Factory
            EFUnitOfWorkFactory ctxFactory = new EFUnitOfWorkFactory(this.ConnectionString(), typeof(DomainContext));

            if (!ctxFactory.DatabaseExists())
            {
                ctxFactory.CreateDatabase();
            }

            ctxFactory.ValidateDatabaseSchema();

            this.unityContainer.RegisterInstance<IDatabaseManager>(ctxFactory);
            this.unityContainer.RegisterInstance<IUnitOfWorkFactory>(ctxFactory);

            this.unityContainer.RegisterType<DbContext, DomainContext>(new InjectionFactory((c) =>
            {
                return ctxFactory.CurrentDbContext;
            }));

            // Repositories
            //this.unityContainer.RegisterType<categoryRepository, categoryRepository>(new PerResolveLifetimeManager());

            UnityControllerFactory factory = new UnityControllerFactory(unityContainer);
            ControllerBuilder.Current.SetControllerFactory(factory);
        }
コード例 #2
0
 public EFUnitOfWork(DbContext context, IUnitOfWork previous, EFUnitOfWorkFactory factory)
 {
     this.dbContext = context;
     this.Previous = previous;
     this.factory = factory;
 }
コード例 #3
0
 public EFUnitOfWork(DbContext context, IUnitOfWork previous, EFUnitOfWorkFactory factory)
 {
     this.dbContext = context;
     this.Previous  = previous;
     this.factory   = factory;
 }