protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();

            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());
            builder.RegisterModule(new ViewModelModule());

            builder.RegisterType(typeof(NavigationService)).As(typeof(INavigationService)).InstancePerRequest();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #2
0
        private static void SetupExtensibility(Autofac.ContainerBuilder builder, bool withAspects)
        {
            var dynamicProxy  = new CastleDynamicProxyProvider();
            var aopRepository = new AspectRepository(dynamicProxy);

            var assemblies = NGS.Utility.AssemblyScanner.GetAssemblies().Where(it => it.FullName.StartsWith("NGS."));

            builder.RegisterInstance(new PluginsConfiguration {
                Assemblies = assemblies
            });

            builder.RegisterType <SystemInitialization>();
            builder.RegisterType <AutofacObjectFactory>().As <IObjectFactory>().SingleInstance();
            builder.RegisterType <AutofacMefProvider>().As <IExtensibilityProvider>().SingleInstance();
            builder.RegisterGeneric(typeof(PluginRepository <>)).As(typeof(IPluginRepository <>)).SingleInstance();

            builder.RegisterInstance(aopRepository).As <IAspectRegistrator, IAspectComposer, IInterceptorRegistrator>();
            builder.RegisterInstance(dynamicProxy).As <IMixinProvider, IDynamicProxyProvider>();

            if (withAspects)
            {
                var autofacModules =
                    from type in NGS.Utility.AssemblyScanner.GetAllTypes()
                    where type.IsPublic && typeof(Autofac.Module).IsAssignableFrom(type) && type.GetConstructor(new Type[0]) != null
                    select type;
                foreach (var m in autofacModules)
                {
                    builder.RegisterModule((Autofac.Module)Activator.CreateInstance(m));
                }
                builder.RegisterModule(new AspectsModule(aopRepository));
            }
        }
Beispiel #3
0
		public void SetUp()
		{
			var builder = new ContainerBuilder();
			builder.RegisterModule<CoreModule>();
			builder.RegisterModule<LuaModule>();
			this.container = builder.Build();
		}
        public static void Configure()
        {
            var builder = new ContainerBuilder();

            var config = GlobalConfiguration.Configuration;

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            //builder.RegisterWebApiFilterProvider(config);
            var dbPath = WebConfigurationManager.AppSettings["sqLiteDb"].Replace(@"~\", "");
            bool useDiskConnOnlyValue;
            if (!bool.TryParse(WebConfigurationManager.AppSettings["useDiskConnOnly"], out useDiskConnOnlyValue))
            {
                throw new InvalidOperationException("Invalid useDiskCOnnOnly in web.config");
            }

            var lucenceIndeDirectory = WebConfigurationManager.AppSettings["lucenceIndeDirectory"].Replace(@"~\", "");

            builder.RegisterModule(new LuceneIndexModule(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, lucenceIndeDirectory)));

            builder.RegisterModule(new ConnectionManagerModule(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dbPath), useDiskConnOnlyValue));
            builder.RegisterModule(new LocationControllerModule());

            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
        /// <summary>
        /// Creates the DI container for the application.
        /// </summary>
        /// <param name="storageDirectory">The directory that will contain the files for the current set of tests.</param>
        /// <param name="hostId">The endpoint ID of the host application.</param>
        /// <returns>The DI container.</returns>
        public static IContainer CreateContainer(string storageDirectory, EndpointId hostId)
        {
            var builder = new ContainerBuilder();
            {
                builder.RegisterModule(new UtilitiesModule());
                builder.RegisterModule(
                    new CommunicationModule(
                        new List<CommunicationSubject>
                            {
                                CommunicationSubjects.TestExecution,
                            },
                        new List<ChannelType>
                            {
                                ChannelType.NamedPipe,
                            },
                        false));

                builder.Register(
                        c =>
                        {
                            var ctx = c.Resolve<IComponentContext>();
                            return BuildReportFileUploader(ctx, storageDirectory, hostId);
                        })
                    .SingleInstance();

                RegisterFileSystem(builder);
                RegisterCore(builder, storageDirectory);
                RegisterCommands(builder);
                RegisterNotifications(builder);
                RegisterTestStepProcessors(builder);
            }

            return builder.Build();
        }
Beispiel #6
0
        protected void Application_Start()
        {
            SessionScope.SetSessionScopeService(new WebSessionScopeService());
            RequestScope.SetRequestScopeService(new WebRequestScopeService());

            var builder = new ContainerBuilder();

            builder.RegisterModule<ServiceModule>();
            builder.RegisterModule<DomainModule>();
            builder.RegisterModule<QueryModelModule>();

            builder.Register(a => new AutofacDependencyResolver(() => CurrentLifetimeScope, DependencyResolver.Current))
                   .As<IDependencyResolver>()
                   .SingleInstance();

            builder.RegisterType<AutofacControllerFactory>().As<IControllerFactory>().SingleInstance();

            builder.RegisterType<DotLessCompiler>().AsSelf().SingleInstance();

            RegisterComponents(builder);

            _container = builder.Build();

            CurrentLifetimeScope = _container.BeginLifetimeScope();

            DependencyResolver.SetResolver(_container.Resolve<IDependencyResolver>());

            RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            RouteTable.Routes.MapRoute("Login", "login", new { controller = "account", action = "login" });

            RouteTable.Routes.MapRoute("Default", "{controller}/{action}/{id}",
                                       new {controller = "Dashboard", action = "Index",
                                       id = UrlParameter.Optional});
        }
        public static void Setup()
        {
            var builder = new ContainerBuilder();

            // Register controllers
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // Register modules
            builder.RegisterModule(new ServiceBusModule());
            builder.RegisterModule(new NHibernateSessionModule());
            builder.RegisterModule(new TranslationServiceModule());
            builder.RegisterModule(new LoggerModule());

            // Register types
            builder.RegisterType<ApplicationSettings>().As<IApplicationSettings>().SingleInstance();
            builder.RegisterType<InMemoryKeyValueCache>().As<IKeyValueCache>().SingleInstance();
            builder.RegisterType<TranslationRepository>().As<ITranslationRepository>();
            builder.RegisterType<UserRepository>().As<IUserRepository>();
            builder.RegisterType<LogRepository>().As<ILogRepository>();
            builder.RegisterType<DefaultEncryptor>().As<IEncryptor>();
            builder.RegisterType<CultureService>().As<ICultureService>();
            builder.Register(c => new RegularExpressionPasswordPolicy(c.Resolve<IApplicationSettings>().PasswordPolicy)).As<IPasswordPolicy>();

            Container = builder.Build();

            // Enables autofac to resolve controllers instead of default asp.net mvc implementation
            DependencyResolver.SetResolver(new AutofacDependencyResolver(Container));
        }
Beispiel #8
0
        // ConfigureContainer is where you can register things directly
        // with Autofac. This runs after ConfigureServices so the things
        // here will override registrations made in ConfigureServices.
        // Don't build the container; that gets done for you by the factory.
        // ReSharper disable once UnusedMember.Global
        public void ConfigureContainer(Autofac.ContainerBuilder builder)
        {
            // Register your own things directly with Autofac here. Don't
            // call builder.Populate(), that happens in AutofacServiceProviderFactory
            // for you.
            builder.RegisterType <AkkaGameService>()
            .As <IGameService>()
            .SingleInstance();


            var connectionString = Configuration.GetSection("ConnectionString").Value;

            builder.RegisterType <CoreWarsDataContext>()
            .WithParameter("connectionString", connectionString)
            .As <CoreWarsDataContext>()
            .AsImplementedInterfaces();

            builder.RegisterType <AggregatedCompetitorFactory>();

            builder
            .RegisterType <SelectMaxRandomCollectionSelectionStrategy <IActorRef> >()
            .AsImplementedInterfaces();

            builder.RegisterType <PlayerSet <IActorRef> >()
            .AsImplementedInterfaces();

            builder.RegisterModule <PythonScriptingModule>();
            builder.RegisterModule <DilemmaModule>();
            builder.RegisterModule <TicTacToeModule>();
        }
        protected override void Load(ContainerBuilder builder)
        {
            // Specific registrations and initialization:
            Plugins.SetInitializationLogging(DeploymentUtility.InitializationLogProvider);

            if (_deploymentTime)
            {
                builder.RegisterModule(new DatabaseGeneratorModuleConfiguration(_shortTransaction));
                builder.RegisterType<DataMigration>();
                builder.RegisterType<DatabaseCleaner>();
                builder.RegisterType<ApplicationGenerator>();
                Plugins.FindAndRegisterPlugins<IGenerator>(builder);
            }
            else
            {
                builder.RegisterType<ApplicationInitialization>();
                Plugins.FindAndRegisterPlugins<IServerInitializer>(builder);
            }

            // General registrations:
            builder.RegisterModule(new Rhetos.Configuration.Autofac.DefaultAutofacConfiguration(_deploymentTime, _deployDatabaseOnly));

            // Specific registrations override:
            builder.RegisterType<ProcessUserInfo>().As<IUserInfo>();
            builder.RegisterInstance(DeploymentUtility.InitializationLogProvider).As<ILogProvider>(); // InitializationLogProvider allows overriding deployment logging (both within and outside IoC).

            base.Load(builder);
        }
        /// <summary>
        /// Creates the DI container for the application.
        /// </summary>
        /// <param name="context">The application context that controls when the application will terminate.</param>
        /// <param name="storageDirectory">The directory in which all the uploaded files are stored.</param>
        /// <returns>The DI container.</returns>
        public static IContainer CreateContainer(ApplicationContext context, string storageDirectory)
        {
            var builder = new ContainerBuilder();
            {
                builder.RegisterInstance(context)
                    .As<ApplicationContext>()
                    .ExternallyOwned()
                    .SingleInstance();

                builder.RegisterModule(new UtilitiesModule());
                builder.RegisterModule(
                    new CommunicationModule(
                        new List<CommunicationSubject>
                            {
                                CommunicationSubjects.TestTransfer,
                                CommunicationSubjects.TestExecution,
                            },
                        new List<ChannelType>
                            {
                                ChannelType.NamedPipe,
                                ChannelType.TcpIP,
                            },
                        true));

                RegisterFileSystem(builder);
                RegisterReports(builder);
                RegisterInformation(builder);
                RegisterNotifications(builder);
                RegisterCommands(builder, storageDirectory);
            }

            return builder.Build();
        }
        public void verify_usage_across_multiple_registration_modules()
        {
            var module1 = new SimplePipelineModule(item =>
            {
                item.RegisterPipeline<MultipipelineTests.In, MultipipelineTests.Out>()
                    .Bind<MultipipelineTests.InOutTranslator>();

                item.RegisterPipeline<string, int, string>("foo")
                    .Bind(p => (p * 3).ToString());

            });

            var module2 = new SimplePipelineModule(item => item.RegisterPipeline<int, string>()
                                                               .Bind(p => (p * 2).ToString()));

            var builder = new ContainerBuilder();
            builder.RegisterModule(module1);
            builder.RegisterModule(module2);

            var ctx = builder.Build();

            var value1 = ctx.Resolve<Functor<MultipipelineTests.In, MultipipelineTests.Out>>()(new MultipipelineTests.In()).NewValue;
            var value2 = ctx.Resolve<Functor<int, string>>()(10);
            var value3 = ctx.Resolve<Functor<string, int, string>>()("foo", 10);

            Assert.That(value1, Is.EqualTo(20));
            Assert.That(value2, Is.EqualTo("20"));
            Assert.That(value3, Is.EqualTo("30"));
        }
Beispiel #12
0
        public Bootstrapper()
        {
            Naru.Core.UnhandledExceptionHandler.InstallDomainUnhandledException();
            Naru.TPL.UnhandledExceptionHandler.InstallTaskUnobservedException();

            IContainer container = null;

            var builder = new ContainerBuilder();

            builder.RegisterModule(new Log4NetModule
                                            {
                                                SectionName = "CommonLogging.Nitrogen.Server"
                                            });

            builder.RegisterModule(new AgathaServerModule
                                   {
                                       ContainerFactory = () => container,
                                       HandlerAssembly = typeof(AssemblyHook).Assembly,
                                       RequestResponseAssembly = typeof(Common.AssemblyHook).Assembly
                                   });

            container = builder.Build();

            Console.WriteLine("EndPoint - {0}", END_POINT);

            var baseAddress = new Uri(END_POINT);
            Host = new ServiceHost(typeof(WcfRequestProcessor), baseAddress);
            Host.Open();
        }
        // Perform registration that should have an application lifetime
        protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
        {
            _logger.Debug("ConfigureApplicationContainer");

            base.ConfigureApplicationContainer(existingContainer);

            //When using assembly scanning with IIS applications, you can run into a little trouble depending on how you do the assembly location. (This is one of our FAQs)

            //When hosting applications in IIS all assemblies are loaded into the AppDomain when the application first starts, but when the AppDomain is recycled by IIS the assemblies are then only loaded on demand.

            //To avoid this issue use the GetReferencedAssemblies() method on System.Web.Compilation.BuildManager to get a list of the referenced assemblies instead:
            //var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies().Cast<Assembly>();

            var asms = AppDomain.CurrentDomain.GetAssemblies();
            //.Where(asm =>asm.GetCustomAttributes().Any(attr => attr.GetType() == typeof(IncludeInNancyAssemblyScanningAttribute)));

            var builder = new ContainerBuilder();
            //foreach (var asm in asms)
            //{
            //    builder.RegisterAssemblyTypes(asm).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces();
            //}
            builder.RegisterModule<Nancy.Demo.Data.DataModule>();
            builder.RegisterModule<NancyDemo.Services.ServiceModule>();

            builder.RegisterType<Tokenizer>().As<ITokenizer>();

            builder.Update(existingContainer.ComponentRegistry);
        }
        public static IContainer ConfigureContainerWebApi()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(AutofacConfig).Assembly).PropertiesAutowired();

            builder.RegisterSource(new ViewRegistrationSource());

            // Register dependencies in filter attributes
            builder.RegisterFilterProvider();

            // Register our Data dependencies
            builder.RegisterModule(new DataModule(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString));

            //builder.RegisterModule(new MvcSiteMapProviderModule());

            // Register Common module
            builder.RegisterModule(new CommonModule());

            builder.RegisterModule(new ServiceModule());

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // Set MVC DI resolver to use our Autofac container
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            return container;
        }
Beispiel #15
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            AutoMapperConfiguration.Configure();

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();


            builder.RegisterType <GameController>().InstancePerRequest();
            builder.RegisterType <PlayerController>().InstancePerRequest();
            builder.RegisterType <TeamController>().InstancePerRequest();
            builder.RegisterType <StatTypeController>().InstancePerRequest();
            builder.RegisterType <PositionController>().InstancePerRequest();
            builder.RegisterType <StatLineController>().InstancePerRequest();
            builder.RegisterType <AccountController>().InstancePerRequest();

            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            var container = builder.Build();

            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            var env = new ApplicationEnvironment();
            var bootupConfigurationProvider = new BootupConfigurationProvider(env);

            Autofac.ContainerBuilder cb = new Autofac.ContainerBuilder();
            cb.RegisterInstance <IEnvironment>(env);
            cb.RegisterInstance(bootupConfigurationProvider).As <IBootupConfigurationProvider>();

            cb.RegisterModule <Teleware.Foundation.Core.Module>();
            cb.RegisterModule <Teleware.Foundation.Configuration.Module>();
            cb.RegisterModule <Teleware.Foundation.Diagnostics.Loggers.NLog.Module>();
            cb.RegisterModule <Teleware.Foundation.Data.Memory.Module>();
            //cb.RegisterModule<Teleware.Foundation.Data.EntityFramework.Module>();
            //cb.RegisterModule<Teleware.Foundation.Data.EntityFramework.Oracle.Module>();

            var container = cb.Build();

            using (var lt = container.BeginLifetimeScope())
            {
                while (true)
                {
                    var db = lt.Resolve <IOptions <DatabaseOptions> >();

                    Console.WriteLine(db.Value.ConnectionStrings.First().ToString());
                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #17
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Autofac Configuration
            var config = GlobalConfiguration.Configuration;

            var builder = new Autofac.ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            //builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();


            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            //var container = builder.Build();

            var container = builder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            //config.DependencyResolver = new au
            //DependencyResolver.SetResolver(new AutofacWebApiDependencyResolver(container));
        }
        public void InMemory_Request_Retrieve_Mock_Test()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule<ProcessingConsumerModule>();
            builder.RegisterModule<BillingConsumerModule>();
            builder.RegisterModule<UserManagementConsumerModule>();

            var itemList = new List<Item>();
            itemList.Add(new Item { Info = "mockResponse" });
            var mockItemRepository = new Mock<IRepository<Item>>();

            mockItemRepository.Setup(rep =>
                rep.Query(It.IsAny<Expression<Func<Item, bool>>>()))
                   .Returns(itemList.AsQueryable());
            builder.Register(c =>
                mockItemRepository.Object).As<IRepository<Item>>();

            using (var service = Service.InMemory(builder).Start())
            {
                var msg = new RequestItemMessage("mockSelection");
                var client = service.CreateRequestClient<RequestItem, ItemResponse>();
                var response = client.Request(msg).Result;
                Assert.AreEqual("mockResponse", response.ItemInfo);
            }
        }
Beispiel #19
0
        private static void SetupContainer()
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType<Logger>().As<ILogger>();

            builder.RegisterType<AutofacServiceProvider>()
                .As<Xdore.Core.IServiceProvider>()
                .InstancePerLifetimeScope();

            #region Modules

            builder.RegisterModule<AutofacWebTypesModule>();
            builder.RegisterModule<DataAccessRegistrationModule>();
            builder.RegisterModule<ServicesRegistrationModule>();

            #endregion

            builder.RegisterControllers(Assembly.GetExecutingAssembly())
                .PropertiesAutowired();

            builder.RegisterFilterProvider();

            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            ServiceLocator.Initialize(() =>
            {
                return DependencyResolver.Current.GetService<IServiceProvider>();
            });

            IDbContextFactory dbFactory = DependencyResolver.Current.GetService<IDbContextFactory>();
            dbFactory.InitDbContext();
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //ModelBinders.Binders.DefaultBinder = new CustomModelBinder();

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();


            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());
        }
Beispiel #21
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var builder = new ContainerBuilder();

            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType<AuthenticationService>().As<IAuthenticationService>();
            builder.RegisterModule<AutofacWebTypesModule>();
            builder.RegisterModule<NHibernateModule>();

            // Change controller action parameter injection by changing web.config.
            builder.RegisterType<ExtensibleActionInvoker>().As<IActionInvoker>().InstancePerHttpRequest();

            // MVC integration test items
            builder.RegisterType<InvokerDependency>().As<IInvokerDependency>();

            // DomainServices
            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AssignableTo<DomainService>();
            builder.RegisterModule<AutofacDomainServiceModule>();

            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            DomainService.Factory = new AutofacDomainServiceFactory(new MvcContainerProvider());

            RegisterRoutes(RouteTable.Routes);
        }
Beispiel #22
0
        public Bootstrapper()
        {
            IContainer container = null;

            var builder = new ContainerBuilder();

            builder.RegisterModule(new AgathaClientModule
                                   {
                                       ContainerFactory = () => container,
                                       RequestResponseAssembly = typeof (Nitrogen.Common.AssemblyHook).Assembly
                                   });

            builder.RegisterModule(new Log4NetModule {SectionName = "CommonLogging.Nitrogen.Client"});

            builder.RegisterType<MessageStream>().As<IMessageStream>().SingleInstance();

            builder.RegisterType<ShellViewModel>().AsSelf();

            builder.RegisterModule(new WPFModule());
            builder.RegisterType<WPFStartable>().AsSelf();

            builder.RegisterType<ClientStartable>().AsSelf();

            // DataExplorer
            builder.RegisterModule(new DataExplorerModule());
            builder.RegisterType<DataExplorerStartable>().AsSelf();

            // Build the container
            container = builder.Build();

            // TODO : Ideally change this, so it isn't resolved like this
            container.Resolve<WPFStartable>().Start();
            container.Resolve<ClientStartable>().Start();
            container.Resolve<DataExplorerStartable>().Start();
        }
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(@"../../../log4net.xml"));

            var builder = new ContainerBuilder();
            builder.RegisterModule(new BusConfigModule());

            // use ravendb
            builder.RegisterModule(new RavenStorageConfigModule());

            // or use nhibernte
            //builder.RegisterModule(new NHibernateStorageConfigModule());

            using (var container = builder.Build())
            {
                Console.WriteLine("Denormalizer Listening...");
                var transport = container.Resolve<ITransportMessages>();
                transport.StartListening();

                Console.WriteLine("Waiting...");
                Console.ReadKey();
                Console.WriteLine("Stopping...");
                transport.StopListening();
            }
        }
Beispiel #24
0
        void Application_Start(object sender, EventArgs e)
        {
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());
            GlobalConfiguration.Configure(WebApiConfig.Register);
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            BaseFrontendMappings.Initialize();

            InitializerModule.InitializeDb();

            AddTask("RemoveUsers", 3600);

            var config = GlobalConfiguration.Configuration;

            //Autofac Configuration
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModule(new MapperModule());
            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new ContractModule());
            builder.RegisterModule(new EfModule());
            builder.RegisterModule(new BaseFrontendModule());

            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
        private void Bootstrap()
        {
            _jobModelRegistry = new ConcurrentDictionary<string, JobModel>();

            _compositionContainer = new CatalogConfigurator()
               .AddAssembly(Assembly.GetExecutingAssembly())
               .AddNestedDirectory(Config.JobsFolderName)
               .BuildContainer();


            _compositionContainer.ComposeParts(this);

            InitTasksRegistry();

            _appContainerBuilder = new ContainerBuilder();
            _appContainerBuilder.RegisterModule<WorkerModule>();
            _appContainerBuilder.RegisterModule<HostingModule>();
            _appContainer = _appContainerBuilder.Build();

            //TODO: make onchanged to an event
            _fileSystemWatcher = new JobsWatcher { OnChanged = OnChanged };
            _fileSystemWatcher.Watch(TasksFolderPath);

            _logger = _appContainer.Resolve<ILogger>();

            _logger.Info("[START] PanteonEngine");

            Task.Run(() => MountApi());
        }
Beispiel #26
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinders(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinderProvider();
            builder.RegisterModule(new RepositoryModule());

            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());
            builder.RegisterModule(new LoggingModule());
            builder.RegisterModule(new AutoMapperModule());
            //builder.RegisterModule(new RedisModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
        }
        private IContainer BuildContainer()
        {
            // Use 'InstancePerLifetimeScope' to create instance which will be shared during the consuming of one message

            var builder = new ContainerBuilder();

            builder.RegisterModule(new ServiceBusModule());
            builder.RegisterModule(new TranslationServiceModule());
            builder.RegisterModule(new MailerModule());

            // Register razor mail message factory (have not found a way to put this in a module, due to the dependencyResolver parameter)
            builder.RegisterType<RazorMailMessageFactory>()
                .WithParameter(new NamedParameter("templateResolver", new DefaultTemplateResolver("Infrastructure", "TemplateMailMessages")))
                .WithParameter(new NamedParameter("templateBase", typeof(ViewBaseClass<>)))
                .WithParameter(new NamedParameter("dependencyResolver", new Func<Type, object>(x => _container.Resolve(x))))
                .WithParameter(new NamedParameter("templateCache", new InMemoryTemplateCache()))
                .As<IRazorMailMessageFactory>()
                .InstancePerLifetimeScope();

            builder.Register(c => NHibernateHelper.SessionFactory).SingleInstance();
            builder.Register(c => c.Resolve<ISessionFactory>().OpenSession()).As<ISession>().InstancePerLifetimeScope();
            builder.RegisterType<InMemoryKeyValueCache>().As<IKeyValueCache>().InstancePerLifetimeScope();
            builder.RegisterType<TranslationRepository>().As<ITranslationRepository>().InstancePerLifetimeScope();
            builder.RegisterType<ApplicationSettings>().As<IApplicationSettings>().SingleInstance();
            builder.RegisterType<NLogLogger>().As<ILogger>().InstancePerLifetimeScope();

            return builder.Build();
        }
        protected void Application_Start()
        {
            Bootstrap.Log.Info("Application Start");

            Database.SetInitializer(new MigrateDatabaseToLatestVersion <BlochsTech.Website.Domain.Context.BlochsTechContext, BlochsTech.Website.Domain.Migrations.Configuration>());

            AreaRegistration.RegisterAllAreas();

            GlobalConfiguration.Configure(WebApiConfig.Register);

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();

            builder.RegisterModule(new DataAccessModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new DomainModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #29
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();



            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();

            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Json default settings which only get parent entries not child
            //JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            //{
            //    Formatting = Newtonsoft.Json.Formatting.Indented,
            //    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            //};
        }
Beispiel #30
0
        public static void Main()
        {
            var builder = new ContainerBuilder();
            builder.RegisterModule<DalEFModule>();
            builder.RegisterModule<ProcessingConsumerModule>();
            builder.RegisterModule<BillingConsumerModule>();
            builder.RegisterModule<UserManagementConsumerModule>();

            Console.WriteLine("Initializing...");

            HostFactory.Run(x =>
            {
                x.Service<Service>(s =>
                {
                    s.ConstructUsing(name => Service.ForRabbitMQ(builder));
                    s.WhenStarted(bus => bus.Start());
                    s.WhenStopped(bus => bus.Stop());
                    s.WhenShutdown(bus => bus.Dispose());
                });
                x.RunAsLocalSystem();

                x.SetDescription("SOA MassTranssit RabbitMQ Host");
                x.SetDisplayName("SOA_BUS");
                x.SetServiceName("SOA_BUS");
            });

            Console.WriteLine("Service is initialized");
        }
Beispiel #31
0
        public void Configuration(IAppBuilder app)
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());


            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            var container = builder.Build();

            //DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Set the dependency resolver for MVC.
            var mvcResolver = new AutofacDependencyResolver(container);

            DependencyResolver.SetResolver(mvcResolver);

            // Set the dependency resolver for Web API.
            var webApiResolver = new AutofacWebApiDependencyResolver(container);

            GlobalConfiguration.Configuration.DependencyResolver = webApiResolver;

            ApplicationContainer.Container = container;
        }
Beispiel #32
0
 private static IContainer RegisterModules()
 {
     var builder = new ContainerBuilder();
     builder.RegisterModule<WebApi>();
     builder.RegisterModule<ServiceArchCore>();
     return builder.Build();
 }
Beispiel #33
0
 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterModule(new LogModule());
     builder.RegisterModule(new SecurityModule());
     builder.Register(c => new GZipFilter()).Keyed<IMessageFilter>(ZipMode.GZip).SingleInstance();
     builder.Register(c => new RSACryptoFilter()).Keyed<IMessageFilter>(CryptoMode.RSA).SingleInstance();
     builder.Register(c => new Crc32Filter()).Keyed<IMessageFilter>(ChecksumMode.Crc32).SingleInstance();
     builder.Register(c => new MessageFilterFactory()).AsSelf().SingleInstance();
     builder.Register(c => new Json()).Keyed<ISerializer>(SerializeMode.Json).SingleInstance();
     builder.Register(c => new Protobuf()).Keyed<ISerializer>(SerializeMode.Protobuf).SingleInstance();
     builder.Register(c => new ExceptionCounterFilter()).AsSelf().SingleInstance();
     builder.Register(c => new CommandHandler(c.Resolve<TimeoutNotifyProducerConsumer<AbstractAsyncCommand>>())).AsSelf().SingleInstance();
     builder.Register(c => new DuplexMessageWriterImplV1()).Keyed<IMessageWriter<DuplexMessage>>(MessageVersion.V1).SingleInstance();
     builder.Register(c => new DuplexMessageReaderImplV1()).Keyed<IMessageReader<DuplexMessage>>(MessageVersion.V1).SingleInstance();
     builder.RegisterType<TimeoutNotifyProducerConsumer<AbstractAsyncCommand>>()
         .WithParameter(new NamedParameter("capacity", AbstractAsyncCommand.BLOCK_UNTIL_TIMEOUT_QUEUE_CAPACITY))
         .AsSelf()
         .SingleInstance()
         .OnActivated(o =>
         {
             o.Instance.OnConsume += (sender, e) =>
             {
                 var consumingItem = e.ConsumingItem as ChunkedConsumingItem<AbstractAsyncCommand>;
                 if (consumingItem == null) return;
                 foreach (var item in consumingItem.Chunk)
                 {
                     try
                     {
                         item.RunAsync();
                     }
                     catch (Exception) { }
                 }
             };
         });
 }
        public static void Setup()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            // Register for API Controllers
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterFilterProvider();
            builder.RegisterModelBinderProvider();
            builder.RegisterModule<AutofacWebTypesModule>();

            // Find all autofac modules and include them.
            builder.RegisterModule<IdentityModule>();

            // Find all IStartable tasks and register them.
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
            builder.RegisterAssemblyTypes(assemblies)
                .AssignableTo<IStartable>()
                .As<IStartable>()
                .SingleInstance();

            // Enable property injection into action filters (including authorize attribute).
            builder.RegisterFilterProvider();

            IContainer container = builder.Build();
            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
 /// <see cref="Module.Load"/>
 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterModule<CoreModule>();
     builder.RegisterModule(new PluginModule { PluginLocation = c => c.Resolve<ISettings>().TestDiscoveryPluginLocation });
     builder.RegisterModule<TeamFoundationModule>();
     builder.RegisterModule<PresentationModule>();
 }
        public static IContainer Initialize(ContainerBuilder builder, HttpConfiguration config)
        {
            // Register all controllers
            builder.RegisterApiControllers(typeof(Startup).Assembly);

            // Register Autofac filter provider
            builder.RegisterWebApiFilterProvider(config);

            // Register model binders
            builder.RegisterWebApiModelBinderProvider();

            // Register all Autofac specific IModule implementations
            builder.RegisterAssemblyModules(typeof(Startup).Assembly);
            builder.RegisterAssemblyModules(typeof(AutofacMediator).Assembly);

            builder.RegisterModule(new RequestHandlerModule());
            builder.RegisterModule(new EntityFrameworkModule());
            builder.RegisterModule(new DocumentGeneratorModule());

            // http://www.talksharp.com/configuring-autofac-to-work-with-the-aspnet-identity-framework-in-mvc-5
            builder.RegisterType<IwsIdentityContext>().AsSelf().InstancePerRequest();
            builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
            builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
            builder.RegisterType<ApplicationUserManager>().As<UserManager<ApplicationUser>>().InstancePerRequest();

            return builder.Build();
        }
Beispiel #37
0
        protected void Application_Start()
        {
            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());
            builder.RegisterModule(new AutofacWebTypesModule());
            builder.RegisterModule(new HelperModule());
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            //Automapper
            AutoMapperConfiguration.Configure();

            log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //register BForms validation provider
            ModelValidatorProviders.Providers.Add(new BsModelValidatorProvider());
            BForms.Utilities.BsResourceManager.Register(Resources.Resources.ResourceManager);
        }
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(@"../../../log4net.xml"));

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterModule(new BusConfigModule());

            // use raven
            builder.RegisterModule(new RavenConfigModule());

            // or use nhibernate
            // builder.RegisterModule(new NHibernateConfigModule());

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            containerProvider = new ContainerProvider(builder.Build());

            DependencyResolver.SetResolver(new AutofacDependencyResolver(containerProvider.ApplicationContainer));
        }
Beispiel #39
0
        private bool Compose()
        {
             var builder = new ContainerBuilder();
             try
             {
                 builder.RegisterAssemblyTypes((typeof(DomainModule).Assembly));
                 builder.RegisterAssemblyTypes((typeof(NetworkModule).Assembly));
                 builder.RegisterAssemblyTypes((typeof(ApplicationModule).Assembly));

                 builder.RegisterModule<DomainModule>();
                 builder.RegisterModule<NetworkModule>();
                 builder.RegisterModule<ApplicationModule>();

                 builder.RegisterType<MessageService>().As<IMessageService>();
                 builder.RegisterType<InterfaceSelectionView>().As<IInterfaceSelectionView>();
                 builder.RegisterType<SharesView>().As<ISharesView>();
                 builder.RegisterType<Query>().As<IQuery>();

                 container = builder.Build();
                 builder = new ContainerBuilder();
                 builder.RegisterInstance<IContainer>(container).SingleInstance();
                 builder.Update(container);
                 return true;
             }
             catch
             {
                 return false;
             }
        }
Beispiel #40
0
        public static IContainer Init()
        {
            var builder = new ContainerBuilder();

            builder
                .RegisterType<HostService>()
                .AsSelf();

            builder
                .RegisterType<Foo>()
                .AsSelf();

            LoggerType type;
            if (!Enum.TryParse(ConfigurationManager.AppSettings["HoneyBear.Spy.LoggerType"], true, out type))
                type = LoggerType.NLog;

            Console.WriteLine($"Using {nameof(LoggerType)}={type}");

            switch (type)
            {
                case LoggerType.Serilog:
                    builder.RegisterModule<SpySerilogAutofacModule>();
                    break;
                case LoggerType.NLog:
                    builder.RegisterModule<SpyNLogAutofacModule>();
                    break;
                default:
                    throw new NotSupportedException($"{type} {nameof(LoggerType)} not supported.");
            }
            
            return builder.Build();
        }
        protected override void Load(ContainerBuilder builder)
        {
            //Modules
            builder.RegisterModule<CoreModule>();
            builder.RegisterModule<DataAccessModule>();
            builder.RegisterModule<ServicesModule>();

            //Automapper profiles
            builder.RegisterAssemblyTypes(typeof(BaseJob<>).Assembly)
                .Where(t => typeof(Profile).IsAssignableFrom(t) && !t.IsAbstract)
                .As<Profile>()
                .SingleInstance();

            builder.RegisterInstance(_serviceBus)
                .AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(ThisAssembly)
                .Where(typeof (IJobContext).IsAssignableFrom)
                .AsSelf()
                .PropertiesAutowired()
                .InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(DefaultJobContext<>))
                .As(typeof(IJobContext<>))
                .AsSelf()
                .InstancePerLifetimeScope();
            builder.RegisterAssemblyTypes(ThisAssembly)
                .Where(typeof (IJob).IsAssignableFrom)
                .Where(x => !x.IsAbstract)
                .AsSelf()
                .AsImplementedInterfaces()
                .SingleInstance();
            builder.RegisterType<JobSettingsProvider>().AsSelf().InstancePerDependency();
            builder.RegisterType<JobStartup>().AsSelf().SingleInstance();
        }
Beispiel #42
0
        public static IContainer GetContainer()
        {
            var container = new Autofac.ContainerBuilder();

            container.RegisterModule <DependencyConfigurationFrameworkModule>();
            container.RegisterModule <DependencyConfigurationWebApiModule>();

            return(container.Build());
        }
Beispiel #43
0
        protected override void SetupBuilder(Autofac.ContainerBuilder builder)
        {
            base.SetupBuilder(builder);

            builder.RegisterModule(new Zetbox.API.ApiModule());
            builder.RegisterModule(new Zetbox.API.Client.ClientApiModule());
            builder.RegisterModule(new Zetbox.API.Client.HttpClientModule());
            builder.RegisterModule(new Zetbox.DalProvider.Memory.MemoryProvider());
        }
Beispiel #44
0
 protected override void Load(Autofac.ContainerBuilder builder)
 {
     builder.RegisterInstance(AutoMapperConfig.Initialize())
     .SingleInstance();
     builder.RegisterModule <CommandModule>();
     builder.RegisterModule <RepositoryModule>();
     builder.RegisterModule <MongoModule>();
     builder.RegisterModule <ServiceModule>();
     builder.RegisterModule(new SettingsModule(_configuration));
 }
Beispiel #45
0
        public DiHook(IObjectContainer scenarioContainer)
        {
            this.scenarioContainer = scenarioContainer;

            var builder = new Autofac.ContainerBuilder();

            builder.RegisterModule <AzSearchAutofacModule>();
            builder.RegisterModule <AutofacAcceptanceTestModule>();

            this.autofac = builder.Build().BeginLifetimeScope();
        }
Beispiel #46
0
        public static void ConfigureContainer()
        {
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired(); // mvc controller
            builder.RegisterModule <AutofacWebTypesModule>();
            builder.RegisterModule(new ServiceModule());                                        // Moduel
            //builder.RegisterType<MvcAuthorizeAttribute>().SingleInstance();//先实例化
            //builder.RegisterFilterProvider(); // 标签过滤器filter
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); // mvc
        }
Beispiel #47
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();

            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            //using (var ctx = new Pm3Entities())
            //{
            //    // create and seed the db
            //    //ctx.Database.Initialize(true);

            //    //// load elements to use AccidentCodeService
            //    //var dbf = new DbFactory();
            //    //var acr = new AccidentCodeRepository(dbf);
            //    //var ui = new UnitOfWork(dbf);
            //    //var acs = new AccidentCodeService(acr, ui);

            //    //// add a code to our table
            //    //if (acs.GetAccidentCode("E") == null)
            //    //{
            //    //    var ac = new AccidentCode
            //    //    {
            //    //        AccidentCodeId = "E",
            //    //        Description = "E description"
            //    //    };
            //    //    acs.CreateAccidentCode(ac);
            //    //    acs.SaveAccidentCode();
            //    //}
            //    //else
            //    //{
            //    //    AccidentCode accidentCode = acs.GetAccidentCode("E");
            //    //    accidentCode.Description = "Some Other New description for E";
            //    //    acs.Update(accidentCode);
            //    //    acs.SaveAccidentCode();
            //    //}
            //}
        }
Beispiel #48
0
        private void AutoFacConfiguration()
        {
            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();

            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #49
0
        private void autofacDependency_Resolver()
        {
            //adding mapping
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();      // Register WebApi Controllers

            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new EFModule());

            var container = builder.Build();

            //DependencyResolver.SetResolver(new AutofacDependencyResolver(container));       // Set the MVC DependencyResolver
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);  // Set the WebApi DependencyResolver
        }
Beispiel #50
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();
            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #51
0
        protected void BuildContainer()
        {
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule <AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            builder.RegisterAssemblyTypes(typeof(ChangeNameCommandHandler).Assembly).Where(x => x.Name.EndsWith("Handler")).AsImplementedInterfaces();

            RegisterMediatr(builder);

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #52
0
        private static void SetupExtensibility(Autofac.ContainerBuilder builder)
        {
            var dynamicProxy  = new CastleDynamicProxyProvider();
            var aopRepository = new AspectRepository(dynamicProxy);

            var dllPlugins =
                (from key in ConfigurationManager.AppSettings.AllKeys
                 where key.StartsWith("PluginsPath", StringComparison.OrdinalIgnoreCase)
                 let path = ConfigurationManager.AppSettings[key]
                            let pathRelative = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path)
                                               let chosenPath = Directory.Exists(pathRelative) ? pathRelative : path
                                                                select chosenPath)
                .ToList();

            builder.RegisterInstance(new PluginsConfiguration {
                Directories = dllPlugins
            });

            builder.RegisterType <SystemInitialization>();
            builder.RegisterType <AutofacObjectFactory>().As <IObjectFactory>().SingleInstance();
            builder.RegisterType <AutofacMefProvider>().As <IExtensibilityProvider>().SingleInstance();
            builder.RegisterGeneric(typeof(PluginRepository <>)).As(typeof(IPluginRepository <>)).SingleInstance();

            builder.RegisterInstance(aopRepository).As <IAspectRegistrator, IAspectComposer, IInterceptorRegistrator>();
            builder.RegisterInstance(dynamicProxy).As <IMixinProvider, IDynamicProxyProvider>();

            if (ConfigurationManager.AppSettings["Revenj.AllowAspects"] == "true")
            {
                builder.RegisterModule(new AspectsModule(aopRepository));
            }
        }
Beispiel #53
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <IISOptions>(options => { options.ForwardClientCertificate = false; });
            var containerBuilder = new Autofac.ContainerBuilder();

            containerBuilder.RegisterModule <AutofacModule>();
            return(base.ConfigureServices(services, containerBuilder, ServiceLifetime.Scoped));
        }
Beispiel #54
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();
            builder.RegisterModule(new ServicesModule());
            builder.RegisterModule(new DataModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #55
0
        protected void Application_Start()
        {
            var config = GlobalConfiguration.Configuration;


            // Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());


            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            // Register your Web API controllers.

            builder.RegisterApiControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();
            //OPTIONAL: Register the Autofac filter provider.
            builder.RegisterWebApiFilterProvider(config);

            //OPTIONAL: Register the Autofac model binder provider.
            builder.RegisterWebApiModelBinderProvider();

            //Set the dependency resolver to be Autofac.


            var container = builder.Build();

            //  DependencyResolver.SetResolver(new AutofacWebApiDependencyResolver(container));

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            config.DependencyResolver =
                new AutofacWebApiDependencyResolver(container);



            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            GlobalConfiguration.Configuration.EnsureInitialized();
        }
Beispiel #56
0
        public static void RegisterModule()
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.AppSettings()
                         .CreateLogger();

            //Autofac Configuration
            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();

            builder.RegisterModule(new LoggerModule());
            builder.RegisterModule(new ServiceModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #57
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var builder = new Autofac.ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();
            builder.RegisterModule(new ServiceModule());
            builder.RegisterModule(new EFModule());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            //Database.SetInitializer<EasyLearningDB>(new DbInitializer());
        }
Beispiel #58
0
        protected override void SetupBuilder(Autofac.ContainerBuilder builder)
        {
            base.SetupBuilder(builder);

            builder.RegisterModule(new Zetbox.API.ApiModule());
            builder.RegisterModule(new Zetbox.API.Server.ServerApiModule());

            builder
            .RegisterType <MetaDataResolverMock>()
            .As <IMetaDataResolver>()
            .InstancePerDependency();

            builder.Register(c => new ZetboxContextMock(c.Resolve <IMetaDataResolver>(), null, c.Resolve <ZetboxConfig>(), c.Resolve <Func <IFrozenContext> >(), c.Resolve <InterfaceType.Factory>()))
            .As <IZetboxContext>()
            .As <IFrozenContext>()
            .As <IReadOnlyZetboxContext>()
            .InstancePerDependency();
        }
Beispiel #59
0
        public static void Configure()
        {
            // create ContainerBuilder
            var builder = new Autofac.ContainerBuilder();

            // Register MVC controllers. (MvcApplication is the name of the class in Global.asax.)
            builder.RegisterControllers(typeof(MvcApplication).Assembly)
            .Where(c => c.Name.EndsWith("Controller"));

            // register Common DIModule
            builder.RegisterModule <Project.Common.DIModule>();
            // register Service DIModule
            builder.RegisterModule <Project.Service.DIModule>();

            var container = builder.Build();

            // set the dependency resolver for MVC controllers to use AutofacDependencyResolver
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #60
-1
 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterModule(new EFModule());
     builder.RegisterModule(new RepositoryModule());
     builder.RegisterModule(new CacheModule());
     builder.RegisterType<PermissionCheck>().As<IPermissionCheck>();
 }