diff --git a/src/Libraries/Nop.Core/Infrastructure/NopEngine.cs b/src/Libraries/Nop.Core/Infrastructure/NopEngine.cs index 9589ef6b200..0dd9cd58540 100644 --- a/src/Libraries/Nop.Core/Infrastructure/NopEngine.cs +++ b/src/Libraries/Nop.Core/Infrastructure/NopEngine.cs @@ -47,22 +47,14 @@ protected virtual void RunStartupTasks() protected virtual void RegisterDependencies(NopConfig 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().SingleInstance(); builder.RegisterInstance(this).As().SingleInstance(); builder.RegisterInstance(typeFinder).As().SingleInstance(); - builder.Update(container); //register dependencies provided by other assemblies - builder = new ContainerBuilder(); var drTypes = typeFinder.FindClassesOfType(); var drInstances = new List(); foreach (var drType in drTypes) @@ -71,7 +63,9 @@ protected virtual void RegisterDependencies(NopConfig config) drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList(); foreach (var dependencyRegistrar in drInstances) dependencyRegistrar.Register(builder, typeFinder, config); - builder.Update(container); + + var container = builder.Build(); + this._containerManager = new ContainerManager(container); //set dependency resolver DependencyResolver.SetResolver(new AutofacDependencyResolver(container));