/// <summary> /// Initialize components and plugins in the nop environment. /// </summary> /// <param name="config">Config</param> public void Initialize(ProConfig config) { //register dependencies RegisterDependencies(config); //startup tasks if (!config.IgnoreStartupTasks) { RunStartupTasks(); } }
/// <summary> /// Register dependencies /// </summary> /// <param name="config">Config</param> protected virtual void RegisterDependencies(ProConfig config) { var builder = new ContainerBuilder(); var container = builder.Build(); this._containerManager = new ContainerManager(container); //we create new instance of ContainerBuilder //because Build() or Update() method can only be called once on a ContainerBuilder. //dependencies var typeFinder = new WebAppTypeFinder(); builder = new ContainerBuilder(); builder.RegisterInstance(config).As <ProConfig>().SingleInstance(); builder.RegisterInstance(this).As <IEngine>().SingleInstance(); builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); builder.Update(container); //register dependencies provided by other assemblies builder = new ContainerBuilder(); var drTypes = typeFinder.FindClassesOfType <IDependencyRegistrar>(); var drInstances = new List <IDependencyRegistrar>(); foreach (var drType in drTypes) { drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType)); } //sort drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList(); foreach (var dependencyRegistrar in drInstances) { dependencyRegistrar.Register(builder, typeFinder, config); } builder.Update(container); //set dependency resolver DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, ProConfig config) { //HTTP context and other related stuff builder.Register(c => //register FakeHttpContext when HttpContext is not available HttpContext.Current != null ? (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) : (new FakeHttpContext("~/") as HttpContextBase)) .As <HttpContextBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Request) .As <HttpRequestBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Response) .As <HttpResponseBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Server) .As <HttpServerUtilityBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Session) .As <HttpSessionStateBase>() .InstancePerLifetimeScope(); //web helper //builder.RegisterType<WebHelper>().As<IWebHelper>().InstancePerLifetimeScope(); //controllers builder.RegisterControllers(typeFinder.GetAssemblies().ToArray()); builder.Register <IDbContext>(c => new ProERPContext()).InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope(); builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope(); builder.RegisterType <SiteService>().InstancePerRequest(); builder.RegisterType <BreakdownService>().InstancePerRequest(); builder.RegisterType <PlantService>().InstancePerRequest(); builder.RegisterType <PartService>().InstancePerRequest(); builder.RegisterType <LineService>().InstancePerRequest(); builder.RegisterType <MachineService>().InstancePerRequest(); // builder.RegisterType<SubAssemblyService>().InstancePerRequest(); builder.RegisterType <UserService>().InstancePerRequest(); builder.RegisterType <PreventiveMaintenanceService>().InstancePerRequest(); builder.RegisterType <PreventiveWorkDescriptionService>().InstancePerRequest(); builder.RegisterType <UserAssignmentsService>().InstancePerRequest(); builder.RegisterType <PreventiveReviewHistoryService>().InstancePerRequest(); builder.RegisterType <MaintenanceRequestServices>().InstancePerRequest(); builder.RegisterType <MaintenancePriorityTypeServices>().InstancePerRequest(); builder.RegisterType <MaintenanceUserAssignmentsServices>().InstancePerRequest(); builder.RegisterType <StatusServices>().InstancePerRequest(); builder.RegisterType <ScheduleTypeService>().InstancePerRequest(); //builder.RegisterType<IndentServices>().InstancePerRequest(); builder.RegisterType <PreventiveHoldHistoryService>().InstancePerRequest(); builder.RegisterType <VendorCategoryService>().InstancePerRequest(); builder.RegisterType <VendorService>().InstancePerRequest(); builder.RegisterType <EmployeeTypeService>().InstancePerRequest(); builder.RegisterType <ItemsServices>().InstancePerRequest(); builder.RegisterType <IndentsServices>().InstancePerRequest(); builder.RegisterType <IndentDetailServices>().InstancePerRequest(); builder.RegisterType <IndentStatusServices>().InstancePerRequest(); builder.RegisterType <IndentBudgetServices>().InstancePerRequest(); builder.RegisterType <IndentDetailAttachmentServices>().InstancePerRequest(); builder.RegisterType <DocumentTypeServices>().InstancePerRequest(); builder.RegisterType <DocumentService>().InstancePerRequest(); builder.RegisterType <DocumentHistoryService>().InstancePerRequest(); builder.RegisterType <BreakDownAttachmentServices>().InstancePerRequest(); builder.RegisterType <TemplateService>().InstancePerRequest(); builder.RegisterType <UtilityService>().InstancePerRequest(); builder.RegisterType <ReportService>().InstancePerRequest(); builder.RegisterType <DashboardService>().InstancePerRequest(); builder.RegisterType <FormulationRequestService>().InstancePerRequest(); builder.RegisterType <RMItemService>().InstancePerRequest(); builder.RegisterType <ProductService>().InstancePerRequest(); builder.RegisterType <WIPStoreService>().InstancePerRequest(); }
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, ProConfig config) { //we cache presentation models between requests builder.RegisterType <HomeController>() .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("pro_cache_static")); builder.RegisterType <SiteController>() .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("pro_cache_static")); //builder.RegisterType<BreakdownController>() // .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("pro_cache_static")); builder.RegisterType <PreventiveMaintenanceController>() .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("pro_cache_static")); builder.RegisterType <Reports.ReportTemplate>() .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("pro_cache_static")); builder.RegisterType <DownloadController>() .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("pro_cache_static")); builder.RegisterType <FormulationRequestController>() .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("pro_cache_static")); builder.RegisterType <ProductController>() .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("pro_cache_static")); builder.RegisterType <RMItemController>() .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("pro_cache_static")); }
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, ProConfig config) { //HTTP context and other related stuff builder.Register(c => //register FakeHttpContext when HttpContext is not available HttpContext.Current != null ? (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) : (new FakeHttpContext("~/") as HttpContextBase)) .As <HttpContextBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Request) .As <HttpRequestBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Response) .As <HttpResponseBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Server) .As <HttpServerUtilityBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Session) .As <HttpSessionStateBase>() .InstancePerLifetimeScope(); //web helper //builder.RegisterType<WebHelper>().As<IWebHelper>().InstancePerLifetimeScope(); //controllers builder.RegisterControllers(typeFinder.GetAssemblies().ToArray()); builder.Register <IDbContext>(c => new ProSchoolContext()).InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope(); builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope(); builder.RegisterType <InfrastructureService>().InstancePerRequest(); builder.RegisterType <InstitutionService>().InstancePerRequest(); builder.RegisterType <FeeService>().InstancePerRequest(); builder.RegisterType <StudentService>().InstancePerRequest(); builder.RegisterType <InquiryService>().InstancePerRequest(); builder.RegisterType <StudentProgramService>().InstancePerRequest(); builder.RegisterType <StudentProgramInvoiceService>().InstancePerRequest(); builder.RegisterType <SystemService>().InstancePerRequest(); }