/// <summary> /// Register dependencies /// </summary> /// <param name="config">Config</param> protected virtual void RegisterDependencies(GoldStoreConfig config) { var builder = new ContainerBuilder(); //dependencies var typeFinder = new WebAppTypeFinder(); builder.RegisterInstance(config).As <GoldStoreConfig>().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(GoldStoreConfig 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 and plugins in the nop environment. /// </summary> /// <param name="config">Config</param> public void Initialize(GoldStoreConfig config) { //register dependencies RegisterDependencies(config); //register mapper configurations RegisterMapperConfiguration(config); //startup tasks if (!config.IgnoreStartupTasks) { RunStartupTasks(); } }
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, GoldStoreConfig config) { string connectionString = "GoldStore"; //controllers builder.RegisterControllers(typeFinder.GetAssemblies().ToArray()); builder.Register <IDbContext>(c => new GoldStoreObjectContext(connectionString)).InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope(); builder.RegisterType <OrderService>().As <IOrderService>().InstancePerLifetimeScope(); builder.RegisterType <ProductService>().As <IProductService>().InstancePerLifetimeScope(); //https://www.entityframeworktutorial.net/code-first/configure-many-to-many-relationship-in-code-first.aspx //https://github.com/entityframeworktutorial/EF6-Code-First-Demo //https://stackoverflow.com/questions/16490334/how-to-define-many-to-many-relationship-through-fluent-api-entity-framework //https://stackoverflow.com/questions/32517747/3-way-many-to-many-with-fluent-api //https://stackoverflow.com/questions/19342908/how-to-create-a-many-to-many-mapping-in-entity-framework }