public static void RegisterDependencies()
        {
            var builder = new ContainerBuilder();

            var config = GlobalConfiguration.Configuration;

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(config);
            builder.RegisterWebApiModelBinderProvider();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            var modules = new Autofac.Module[] {
                new UniversityDbContextModule(),
                new RepositoryModule(),
                new RegistrationModule(),
                new PasswordModule(),
                new AuthenticationModule(),
                new AuthorizationModule(),
                new EditingModule()
            };

            foreach (var module in modules)
            {
                builder.RegisterModule(module);
            }

            var container = builder.Build();

            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
        public static void Initialize(Module module)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterModule(module);

            var container = containerBuilder.Build();

            ComponentLocator.Initialize(container);
        }
Esempio n. 3
0
        public void Register(Module consumerModule)
        {
            var builder = new ContainerBuilder();
            builder.RegisterModule(consumerModule);
            //builder.RegisterModule<NhModule>();
            //builder.RegisterModule<EfModule>();
            //builder.RegisterModule<DomainServiciesModule>();
            builder.RegisterModule<ClientModule>();

            _container = builder.Build();
        }
Esempio n. 4
0
        private IContainer buildContainer()
        {
            var modules = new Module[] {
            new CoreModule(_settings),
            new WebModule(_settings),
            new DataModule()
              };

              var builder = new ContainerBuilder();
              Array.ForEach(modules, builder.RegisterModule);

              return builder.Build();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <Configuration>(Configuration);
            services.AddOptions();
            services.AddAutoMapper(typeof(MapperProfile));
            var configuration = Configuration.Get <Configuration>();

            services.AddHealthChecks().AddRedis(configuration.CacheName);
            if (AutofacModule == null)
            {
                AutofacModule = new AutofacModule(configuration);
            }
            services.AddCors(options => options.AddPolicy(name: "CorsPolicy", b =>
            {
                b.AllowAnyMethod()
                .AllowAnyHeader()
                .AllowAnyOrigin();
            }));

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title   = "Prime number server",
                    Version = "v1",
                    Contact = new OpenApiContact
                    {
                        Email = "*****@*****.**",
                        Name  = "Szabolcs Simonyi"
                    },
                    Description = "Test application Infinite Lambda, 13. Sept. 2020"
                });
            });
            services.ConfigureSwaggerGen(options =>
            {
                var currentAssembly = Assembly.GetExecutingAssembly();
                var xmlDocs         = currentAssembly.GetReferencedAssemblies()
                                      .Union(new AssemblyName[] { currentAssembly.GetName() })
                                      .Select(a => Path.Combine(Path.GetDirectoryName(currentAssembly.Location), $"{a.Name}.xml"))
                                      .Where(f => File.Exists(f)).ToArray();
                Array.ForEach(xmlDocs, (d) =>
                {
                    options.IncludeXmlComments(d);
                });
            });

            services.AddRouting(options => options.LowercaseUrls = true);
            services.AddControllers();
        }
        private void InitializeApplication(ContainerBuilder builder, Module[] modules)
        {
            builder.RegisterInstance(new DefaultMessageBus()).As<IBus>().SingleInstance();
            builder.RegisterModules(modules);
            builder.RegisterModule(new ViewModelModule());

            ContainerHolder.Initialize(builder.Build());
            MainPage = new NavigationPage(new LoginPage())
            {
				BarBackgroundColor = Color.FromHex("#3C8513"),
				BarTextColor = Color.FromHex("#FCD23C")
            };

            Navigation = MainPage.Navigation;
        }
Esempio n. 7
0
        private IContainer BuildContainer(IConfiguration configuration)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();
            ConfigureLogger(serviceCollection);

            var modules = new Module[]
            {
                new CommonModule(),
                new ApiModule()
            };

            return(serviceCollection.ConfigureAutofacContainer(configuration, b => { }, modules));
        }
Esempio n. 8
0
        private void RegisterModule(AutofacCore.Module module, ContainerBuilder autofacBuilder)
        {
            #region Contracts

            if (module == null)
            {
                throw new ArgumentException();
            }
            if (autofacBuilder == null)
            {
                throw new ArgumentException();
            }

            #endregion

            // Register
            autofacBuilder.RegisterModule(module);
        }
Esempio n. 9
0
        public void RegisterModule(AutofacCore.Module module)
        {
            #region Contracts

            if (module == null)
            {
                throw new ArgumentException();
            }

            #endregion

            // Require
            if (_container != null)
            {
                throw new InvalidOperationException();
            }

            // Delegate
            _registerDelegateList.Add((autofacBuilder) =>
            {
                this.RegisterModule(module, autofacBuilder);
            });
        }
Esempio n. 10
0
 /// <summary>
 /// Executes the Load-method of the specified <see cref="Module"/> on this <see cref="MockContainerBuilder"/>.
 /// </summary>
 /// <param name="module">The module to load</param>
 public void Load(Module module)
 {
     LoadModule.Invoke(module, new object[] { this });
 }
 private void LoadModule(ContainerBuilder bldr, Autofac.Module module, Type clazz)
 {
     bldr.RegisterModule(module);
     Console.WriteLine("Registered Plugin Module: " + clazz.Name);
 }