private void RegisterDependencies(ABOConfig config, params IDependencyRegistrar[] dependencyRegistars) { var builder = new ContainerBuilder(); var container = builder.Build(); // Infrastructure builder = new ContainerBuilder(); builder.RegisterInstance(config).As <ABOConfig>().SingleInstance(); builder.RegisterInstance(this).As <IEngine>().SingleInstance(); builder.Update(container); // Invoke other dependency registrars builder = new ContainerBuilder(); foreach (var depRegistrar in dependencyRegistars) { depRegistrar.Register(builder); } builder.Update(container); // Set container manager _containerManager = new ContainerManager(container, new JobContextManager(container)); //DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
private void RegisterDependencies(ABOConfig config, params IDependencyRegistrar[] dependencyRegistars) { var builder = new ContainerBuilder(); var container = builder.Build(); builder = new ContainerBuilder(); builder.RegisterType <ABODataContext>().Named <IDbContext>("SqlServerContext").SingleInstance(); // Repository builder.RegisterGeneric(typeof(EfRepository <>)).Named("SqlServerRepository", typeof(IRepository <>)) .WithParameter( (pi, ctx) => pi.ParameterType == typeof(IDbContext), (pi, ctx) => ctx.ResolveKeyed <IDbContext>("SqlServerContext")) .InstancePerLifetimeScope(); // Service //builder.RegisterType<AssetService>().Named<IAssetService>("SqlServerService").InstancePerLifetimeScope(); builder.Update(container); // Set container manager _containerManager = new ContainerManager(container, new TestContextManager()); //DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public void Initialize(ABOConfig config, params IDependencyRegistrar[] dependencyRegistars) { RegisterDependencies(config, dependencyRegistars); }