/// <summary> /// Register dependencies /// </summary> /// <param name="config">Config</param> protected virtual void RegisterDependencies(WonderLabsConfig config) { var builder = new ContainerBuilder(); //dependencies var typeFinder = new WebAppTypeFinder(); builder.RegisterInstance(config).As <WonderLabsConfig>().SingleInstance(); builder.RegisterInstance(this).As <IEngine>().SingleInstance(); builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); //register dependencies provided by other assemblies 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); } var container = builder.Build(); this._containerManager = new ContainerManager(container); //set dependency resolver DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
/// <summary> /// Register mapping /// </summary> /// <param name="config">Config</param> protected virtual void RegisterMapperConfiguration(WonderLabsConfig config) { //dependencies var typeFinder = new WebAppTypeFinder(); //register mapper configurations provided by other assemblies var mcTypes = typeFinder.FindClassesOfType <IMapperConfiguration>(); var mcInstances = new List <IMapperConfiguration>(); foreach (var mcType in mcTypes) { mcInstances.Add((IMapperConfiguration)Activator.CreateInstance(mcType)); } //sort mcInstances = mcInstances.AsQueryable().OrderBy(t => t.Order).ToList(); //get configurations var configurationActions = new List <Action <IMapperConfigurationExpression> >(); foreach (var mc in mcInstances) { configurationActions.Add(mc.GetConfiguration()); } //register AutoMapperConfiguration.Init(configurationActions); }
/// <summary> /// Initialize components /// </summary> /// <param name="config">Config</param> public void Initialize(WonderLabsConfig config) { //register dependencies RegisterDependencies(config); //register mapper configurations RegisterMapperConfiguration(config); }
/// <summary> /// Register services and interfaces /// </summary> /// <param name="builder">Container builder</param> /// <param name="typeFinder">Type finder</param> /// <param name="config">Config</param> public void Register(ContainerBuilder builder, ITypeFinder typeFinder, WonderLabsConfig config) { //HTTP context and other related stuff builder.Register(c => (new HttpContextWrapper(HttpContext.Current) as HttpContextBase)) .As <HttpContextBase>() .InstancePerLifetimeScope(); //controllers builder.RegisterControllers(typeFinder.GetAssemblies().ToArray()); //data layer var dataSettingsManager = new DataSettingsManager(); var dataProviderSettings = dataSettingsManager.LoadSettings(); builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>(); builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency(); builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency(); if (dataProviderSettings != null && dataProviderSettings.IsValid()) { var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings()); var dataProvider = efDataProviderManager.LoadDataProvider(); dataProvider.InitConnectionFactory(); builder.Register <IDbContext>(c => new WonderLabsObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope(); } else { builder.Register <IDbContext>(c => new WonderLabsObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope(); } builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope(); builder.RegisterType <SettingService>().As <ISettingService>() .InstancePerLifetimeScope(); builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope(); builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance(); }
/// <summary> /// Register services and interfaces /// </summary> /// <param name="builder">Container builder</param> /// <param name="typeFinder">Type finder</param> /// <param name="config">Config</param> public void Register(ContainerBuilder builder, ITypeFinder typeFinder, WonderLabsConfig config) { builder.RegisterType <SettingModelFactory>().As <ISettingModelFactory>().InstancePerLifetimeScope(); }