Ejemplo n.º 1
0
        private void AutofacConfig()
        {
            var builder  = new ContainerBuilder();
            var assembly = Assembly.GetExecutingAssembly();

            // MVC - Register your MVC controllers.
            builder.RegisterControllers(assembly);

            // MVC - OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule <AutofacWebTypesModule>();

            // MVC - OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // MVC - OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            //注入实现Sintoacct.Ledger.IDependency接口的对象
            builder.RegisterAssemblyTypes(assembly)
            .Where(t => t.GetInterface("Sintoacct.Ledger.IDependency") != null)
            .AsImplementedInterfaces();

            //注入Ledger上下文
            var ledger = new LedgerContext();

            ledger.Database.Initialize(false);
            //#warning 输出SQL
            //ledger.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
            //builder.RegisterInstance(ledger).As<LedgerContext>();
            builder.RegisterType <LedgerContext>().InstancePerLifetimeScope();

            //注入BizProgressContext
            var prog = new BizProgressContext();

            prog.Database.Initialize(false);
            builder.RegisterType <BizProgressContext>().InstancePerLifetimeScope();

            // WebAPI - Register your Web API controllers
            builder.RegisterApiControllers(assembly);

            // WebAPI - OPTIONAL: Register the Autofac filter provider.
            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

            //注入Log4net
            builder.RegisterModule(new LogInjectionModule());


            IContainer container = builder.Build();

            //注入MVC
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            //注入Web API
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Ejemplo n.º 2
0
        public BizProgressService(BizProgressContext progContext,
                                  HttpContextBase context,
                                  IBizCustomer customer,
                                  IBizSetting setting)
        {
            _context  = progContext;
            _identity = context.User.Identity as ClaimsIdentity;
            _customer = customer;
            _setting  = setting;

            _isAdmin = _identity.HasClaim("role", "progress-admin");
        }
Ejemplo n.º 3
0
 public BizSetting(BizProgressContext progContext)
 {
     _context = progContext;
 }
Ejemplo n.º 4
0
 public ReportService(BizProgressContext progContext)
 {
     _context = progContext;
 }
Ejemplo n.º 5
0
 public BizCustomer(BizProgressContext progContext)
 {
     _context = progContext;
 }