コード例 #1
0
        public void RegisterServices(Container container, CompositionRootSettings settings)
        {
            if (settings.FluentValidationAssemblies == null) return;

            ValidatorOptions.CascadeMode = CascadeMode.StopOnFirstFailure;

            container.RegisterSingleton<IValidatorFactory, SimpleInjectorValidatorFactory>();
            container.RegisterSingleton<IProcessValidation, ValidationProcessor>();

            container.Register(typeof(IValidator<>), settings.FluentValidationAssemblies);

            // Add unregistered type resolution for objects missing an IValidator<T>
            container.RegisterConditional(typeof(IValidator<>), typeof(ValidateNothingDecorator<>), Lifestyle.Singleton, context => !context.Handled);
        }
コード例 #2
0
        public static void ConfigureGenerics(Container container)
        {
            container.Register(typeof(DataProvider<>),
                new[] { typeof(DataProvider<>).Assembly }, Lifestyle.Singleton);
            container.Register(typeof(CommandHandler<,>), new[] { typeof(CommandHandler<,>).Assembly });
            container.Register(typeof(CommandHandler<>), new[] { typeof(CommandHandler<>).Assembly });

            var commandHandlerTypes = container.GetTypesToRegister(typeof(Command<>),
                new[] { typeof(Command<>).Assembly },
                    new TypesToRegisterOptions { IncludeGenericTypeDefinitions = true} );

            foreach (Type type in commandHandlerTypes.Where(t => t.IsGenericTypeDefinition))
            {
                container.RegisterConditional(typeof(Command<>), type, c => !c.Handled);
            }
        }
コード例 #3
0
        public static Container GetInitializeContainer(
                  IAppBuilder app)
        {
            var container = new Container();
            container.Options.PropertySelectionBehavior = new ImportPropertySelectionBehavior(); // Enable ImportAttribute for property injection
 
            container.RegisterSingleton(app);

            container.Register<IFederationService, FederationService>(Lifestyle.Singleton);
            container.Register<IAppService, AppService>(Lifestyle.Transient);
 
            container.RegisterConditional(typeof(IRepository<>), typeof(Repository<>), c => !c.Handled);

            container.Register<ICheckPasswordService<AppMember>, LegacyCheckPasswordService<AppMember>>(Lifestyle.Transient);
 
            container.RegisterPerWebRequest<IDragonUserStore<AppMember>>(() =>
            {
                var dragonUserStores = new List<IDragonUserStore<AppMember>>
                {
                    new UserStore<AppMember>(new Repository<AppMember>(), null, new Repository<IdentityUserLogin>(),
                        new Repository<IdentityUserService>(), new Repository<IdentityUserApp>())
                };
                if (WebConfigurationManager.ConnectionStrings[RedisConnectionStringName] != null)
                {
                    var connectionMultiplexer = ConnectionMultiplexer.Connect(WebConfigurationManager.ConnectionStrings[RedisConnectionStringName].ConnectionString);
                    connectionMultiplexer.PreserveAsyncOrder = false;
                    dragonUserStores.Insert(0, new Identity.Redis.UserStore<AppMember>(new RedisUserStore<Identity.Redis.IdentityUser>(connectionMultiplexer), connectionMultiplexer));
                }
                var userStore = new ChainedIdentity.Stores.UserStore<AppMember>(dragonUserStores);
                Startup.OpenIdMigrationWebrequestHandler = new OpenIdMigrationWebRequestHandler(userStore);
                return userStore;
            });

            container.Register<IUserService, UserService>(Lifestyle.Transient);

            container.RegisterPerWebRequest(() => ApplicationUserManager.Create(container, Startup.DataProtectionProvider));

            container.RegisterPerWebRequest(() => container.GetOwinContext().Authentication);

            container.RegisterMvcControllers(
                    Assembly.GetExecutingAssembly());
            
            return container;
        }
コード例 #4
0
        public static Container GetInitializeContainer(
                  IAppBuilder app)
        {
            var container = new Container();
 
            container.RegisterSingleton(app);
 
            container.RegisterConditional(typeof(IRepository<>), typeof(Repository<>), c => !c.Handled);
 
            container.RegisterPerWebRequest<IDragonUserStore<AppMember>>(() =>
                new Dragon.SecurityServer.ChainedIdentity.Stores.UserStore<AppMember>(new List<IDragonUserStore<AppMember>>{
                    new UserStore<AppMember>(new Repository<AppMember>(), new Repository<IdentityUserClaim>(), new Repository<IdentityUserLogin>(), null, null)
                }));
 
            container.RegisterPerWebRequest(() => ApplicationUserManager.Create(container));

            container.RegisterPerWebRequest(() => container.GetOwinContext().Authentication);

            container.RegisterMvcControllers(
                    Assembly.GetExecutingAssembly());
            
            return container;
        }
コード例 #5
0
 public void Resgister(Type IService, Type TImpl, Lifecycle lifecycle)
 {
     _container.RegisterConditional(IService, TImpl, GetLifecyle(lifecycle), c => !c.Handled);
 }
コード例 #6
0
        /// <summary>
        /// Registers all dependencies with the application's container.
        /// </summary>
        /// <param name="container"></param>
        private static void RegisterDependencies(Container container)
        {
            container.Register<IAmikiriConfigurationProvider, AmikiriConfigurationProvider>(Lifestyle.Scoped);
            container.RegisterConditional(
                typeof(ILogger),
                context => typeof(LoggerWrapper<>).MakeGenericType(context.Consumer.ImplementationType),
                Lifestyle.Singleton,
                _ => true);

            ConfigureDelegatingHandlers(container);
            ConfigureAutoMapper(container);
            ConfigureRavenDb(container);
            ConfigureMediatr(container);
            ConfigureFluentValidator(container);
            ConfigureCorsProviders(container);
            ConfigureAspNetIdentity(container);
        }
コード例 #7
0
        public static Container Initialize()
        {
            container.RegisterConditional(typeof(ILogger),
                                          c => typeof(Log4NetAdapter <>).MakeGenericType(c.Consumer.ImplementationType),
                                          Lifestyle.Singleton,
                                          c => true);

            // App Settings
            container.RegisterSingleton <AppSettings>(createAppSettings);
            var  appSettings            = createAppSettings();
            bool isSqlFormsDataProvider = string.Equals(appSettings.formsDataProvider, "sqlFormsDataProvider", StringComparison.InvariantCultureIgnoreCase);

            // Entity Framework Contexts registration
            container.RegisterSingleton <SitecoreForms>(CreateExperienceFormsDbContext);
            container.RegisterSingleton <SourceMasterDb>(createMasterDbSourceContext);
            container.RegisterSingleton <DestMasterDb>(createMasterDbDestContext);
            if (isSqlFormsDataProvider)
            {
                container.RegisterSingleton <Library.Database.WFFM.WFFM>(CreateWffmDbContext);
            }
            else
            {
                container.RegisterSingleton <MongoAnalytics>(createMongoAnalyticsContext);
            }

            // Metadata Provider
            container.Register <IMetadataProvider, MetadataProvider>();

            // Reporting
            container.Register <IReporter, AnalysisReporter>(Lifestyle.Singleton);

            // Repositories
            container.Register <IDestMasterRepository, DestMasterRepository>(Lifestyle.Singleton);
            container.Register <ISourceMasterRepository, SourceMasterRepository>(Lifestyle.Singleton);
            container.Register <ISitecoreFormsDbRepository, SitecoreFormsDbRepository>(Lifestyle.Singleton);

            container.Register <IFieldFactory, FieldFactory>();
            container.Register <IFieldProvider, FieldProvider>();

            container.Register <IItemConverter, ItemConverter>();
            container.Register <IItemFactory, ItemFactory>();

            container.Register <FormProcessor>();
            container.Register <SubmitConverter>();
            container.Register <FormAppearanceConverter>();
            container.Register <SectionAppearanceConverter>();

            container.Register <DataMigrator>();

            container.Register <MetadataValidator>();
            container.Register <AppSettingsValidator>();
            container.Register <DbConnectionStringValidator>();

            RegisterFormsDataProvider();

            // Configuration to registere unregistered converter types
            container.ResolveUnregisteredType += (sender, e) =>
            {
                if (e.UnregisteredServiceType.IsGenericType &&
                    e.UnregisteredServiceType.GetGenericTypeDefinition() == typeof(BaseFieldConverter))
                {
                    object baseConverter = container.GetInstance(typeof(BaseFieldConverter));

                    // Register the instance as singleton.
                    e.Register(() => baseConverter);
                }
            };

            container.Verify();

            return(container);
        }