Пример #1
0
        private IList <IConfigurationSetting> ReadSettings()
        {
            var settings = new List <IConfigurationSetting>();

            // ReSharper disable AssignNullToNotNullAttribute
            var assembliesInCallStack = new StackTrace()
                                        .GetFrames()
                                        .Select(f => f.GetMethod())
                                        .Select(m => m.DeclaringType)
                                        .NotNull()
                                        .Select(t => t.Assembly)
                                        .Distinct()
                                        .ToArray();
            // ReSharper restore AssignNullToNotNullAttribute

            var valueParsers = assembliesInCallStack
                               .SelectMany(a => a.GetExportedTypes())
                               .Where(t => typeof(IValueParser).IsAssignableFrom(t))
                               .Where(t => t.IsInstantiable())
                               .Select(t => (IValueParser)Activator.CreateInstance(t))
                               .ToArray();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(assembliesInCallStack)
            .RegisterWithContainer(settings.Add)
            .WithCustomValueParsers(valueParsers)
            .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(true)
            .DoYourThing();

            return(settings);
        }
Пример #2
0
        protected override void Load(ContainerBuilder builder)
        {
            ConfigurationConfigurator
            .RegisterConfigurationSettings()
            .FromAssemblies(typeof(WebAutofacModule).Assembly)
            .RegisterWithContainer(s => builder.RegisterInstance(s).AsSelf().SingleInstance())
            .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(true)
            .DoYourThing();

            builder.Register(_ => FrankenwikiConfiguration.Create()
                             .WithWikiSourcePath(_.Resolve <WikiSourcePathSetting>())
                             .Build())
            .AsSelf();

            builder
            .RegisterType <Frankengenerator>()
            .As <IFrankengenerator>();
            builder
            .RegisterType <InMemoryFrankenstore>()
            .As <IFrankenstore>()
            .SingleInstance();
            builder
            .RegisterType <InMemoryFrankensearch>()
            .As <IFrankensearch>()
            .SingleInstance();
        }
Пример #3
0
        private static async Task MainAsync()
        {
            var containerBuilder = new ContainerBuilder();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(typeof(Program).Assembly)
            .RegisterWithContainer(configSetting => containerBuilder.RegisterInstance(configSetting)
                                   .AsSelf()
                                   .SingleInstance())
            .DoYourThing();
            containerBuilder.RegisterType <BusConfiguration>().SingleInstance().AsImplementedInterfaces();
            containerBuilder.Register(container =>
            {
                var busConfig       = container.Resolve <IBusConfiguration>();
                var mediatorBuilder = new MediatorBuilder();
                return(mediatorBuilder.RegisterHandlers(typeof(Program).Assembly)
                       .ConfigurePublishPipe(x =>
                {
                    x.UseMessageQueue(() => busConfig,
                                      () => true);
                }).Build());
            }).AsImplementedInterfaces();


            using (var container = containerBuilder.Build())
            {
                var mediator = container.Resolve <IMediator>();
                await mediator.SendAsync(new CalculateTotalCommand(1, 2));
            }
        }
Пример #4
0
 protected override void Load(ContainerBuilder builder)
 {
     ConfigurationConfigurator.RegisterConfigurationSettings()
     .FromAssemblies(ThisAssembly)
     .RegisterWithContainer(configSetting => builder.RegisterInstance(configSetting)
                            .AsSelf()
                            .SingleInstance())
     .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(true)
     .DoYourThing();
 }
Пример #5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            string pathValue     = Environment.GetEnvironmentVariable("PATH");
            string domainBaseDir = AppDomain.CurrentDomain.BaseDirectory;
            string cntkPath      = domainBaseDir + @"bin\";

            pathValue += ";" + cntkPath;
            Environment.SetEnvironmentVariable("PATH", pathValue);

            var builder = new ContainerBuilder();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(CoreAssembly.Assembly)
            .RegisterWithContainer(configSetting => builder.RegisterInstance(configSetting).AsSelf().SingleInstance())
            .ExcludeSettingKeys(new[] {
                "aspnet:PortableCompilationOutput",
                "aspnet:PortableCompilationOutputSnapshotType",
                "aspnet:DisableFcnDaclRead",
                "WEBSITE_AUTH_ENABLED",
                "ScmType",
                "WEBSITE_SITE_NAME",
                "REMOTEDEBUGGINGVERSION",
                "APPINSIGHTS_INSTRUMENTATIONKEY",
                "WEBSITE_NODE_DEFAULT_VERSION",
                "serilog:minimum-level",
                "webpages:Version",
                "webpages:Enabled",
                "ClientValidationEnabled",
                "UnobtrusiveJavaScriptEnabled",
                "autoFormsAuthentication",
                "enableSimpleMembership"
            })
            .DoYourThing();

            builder.RegisterModule <CoreModule>();

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


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

            container.BeginLifetimeScope();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Пример #6
0
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            kernel.Bind <DeepThought>().ToSelf();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(typeof(DeepThought).Assembly)
            .RegisterWithContainer(configSetting => kernel.Bind(configSetting.GetType())
                                   .ToConstant(configSetting))
            .DoYourThing();

            return(kernel);
        }
        public void SetUp()
        {
            var configurationSettings = new List <IConfigurationSetting>();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(Assembly.GetExecutingAssembly())
            .RegisterWithContainer(configurationSettings.Add)
            .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(false)
            .WithCustomValueParsers(new PersonNameValueParser())
            .ExcludeSettingKeys("IgnoredSetting")
            .DoYourThing();

            _somePersonSetting = configurationSettings.OfType <SomePersonSetting>().Single();
        }
 protected override void Load(ContainerBuilder builder)
 {
     ConfigurationConfigurator.RegisterConfigurationSettings()
     .FromAssemblies(new[] {
         Assembly.GetAssembly(typeof(AppEnvironment)),
         ThisAssembly
     })
     .RegisterWithContainer(configSetting => builder.RegisterInstance(configSetting)
                            .AsSelf()
                            .SingleInstance())
     .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(true)
     .ExcludeSettingKeys("ServiceBusConnectionString")
     .DoYourThing();
 }
Пример #9
0
        private static IWindsorContainer CreateContainer()
        {
            var container = new WindsorContainer();

            container.Register(Component.For <DeepThought>());

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(typeof(DeepThought).Assembly)
            .RegisterWithContainer(configSetting => container.Register(Component.For(configSetting.GetType())
                                                                       .Instance(configSetting)
                                                                       .LifestyleSingleton()))
            .DoYourThing();

            return(container);
        }
Пример #10
0
        private static IContainer CreateContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <DeepThought>();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(typeof(DeepThought).Assembly)
            .RegisterWithContainer(configSetting => builder.RegisterInstance(configSetting)
                                   .AsSelf()
                                   .SingleInstance())
            .DoYourThing();

            return(builder.Build());
        }
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(AppDomainScanner.AppDomainScanner.MyAssemblies)
            .RegisterWithContainer(configSetting => builder.RegisterInstance(configSetting)
                                   .AsSelf()
                                   .SingleInstance())
            .ExcludeSettingKeys(
                "webpages:Version",
                "webpages:Enabled",
                "ClientValidationEnabled",
                "UnobtrusiveJavaScriptEnabled")
            .DoYourThing();
        }
Пример #12
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            var webAssembly = typeof(MvcApplication).Assembly;

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(webAssembly)
            .RegisterWithContainer(configSetting => builder.RegisterInstance(configSetting)
                                   .AsSelf()
                                   .SingleInstance())
            .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(true)
            .DoYourThing();

            builder.RegisterType <JwtSettings>()
            .AsSelf()
            .SingleInstance()
            .PropertiesAutowired();
        }
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            var valueParsers = new[] { Constants.ServiceAssembly }
            .SelectMany(a => a.GetExportedTypes())
            .Where(t => typeof(IValueParser).IsAssignableFrom(t))
            .Where(t => t.IsInstantiable())
            .Select(t => (IValueParser)Activator.CreateInstance(t))
            .ToArray();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(Constants.ServiceAssembly)
            .RegisterWithContainer(configSetting => builder.RegisterInstance(configSetting)
                                   .AsSelf()
                                   .SingleInstance())
            .WithCustomValueParsers(valueParsers)
            .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(true)
            .DoYourThing();
        }
        private IList <IConfigurationSetting> ReadSettings()
        {
            var settings = new List <IConfigurationSetting>();

            var valueParsers = _assemblies
                               .SelectMany(a => a.GetExportedTypes())
                               .Where(t => typeof(IValueParser).IsAssignableFrom(t))
                               .Where(t => t.IsInstantiable())
                               .Select(t => (IValueParser)Activator.CreateInstance(t))
                               .ToArray();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(_assemblies)
            .RegisterWithContainer(settings.Add)
            .WithCustomValueParsers(valueParsers)
            .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(true)
            .DoYourThing();

            return(settings);
        }
        private static T ReadSetting <T>(Assembly[] assembliesToScanForValueParsers)
        {
            var settings = new List <IConfigurationSetting>();

            var valueParsers = assembliesToScanForValueParsers
                               .SelectMany(GetDefinedTypes)
                               .Where(t => typeof(IValueParser).IsAssignableFrom(t))
                               .Where(IsInstantiable)
                               .Select(t => (IValueParser)Activator.CreateInstance(t))
                               .ToArray();

            var singleSettingTypeProvider = new ExplicitTypeProvider(new[] { typeof(T) });

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromTypeProvider(singleSettingTypeProvider)
            .RegisterWithContainer(settings.Add)
            .WithCustomValueParsers(valueParsers)
            .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(true)
            .DoYourThing();

            return(settings
                   .OfType <T>()
                   .Single());
        }