private void ConfigureRegistrations(TinyIoCContainer container)
        {
            container.Register(_appConfig);
            container.Register(_logger);
            var options            = new MemoryCacheOptions();
            var eventLogger        = LogFactory.CreateEventLogger(_loggingLevelSwitch, _appConfig.ApplicationInsights);
            var serilogEventWriter = new SerilogEventWriter(eventLogger);

            container.Register <IEventWriter>(serilogEventWriter, "innerEventWriter");
            container.Register(options);
            container.Register <ICouchDbSettings>(_appConfig.CouchDbSettings);
            container.Register <IPropertySettings>(_appConfig.DefaultPropertySettings);
            container.Register(typeof(IOptions <>), typeof(OptionsManager <>));
            container.Register <IMemoryCache, MemoryCache>();

            if (_appConfig.UseInMemoryStores)
            {
                container.RegisterInMemoryStores();
            }
            else
            {
                container.Register <IDocumentDbService, CouchDbAccessService>("inner");
                var dbAccessService = container.Resolve <CouchDbAccessService>();
                dbAccessService.Initialize().Wait();
                dbAccessService.AddViews("roles", CouchDbRoleStore.GetViews()).Wait();
                dbAccessService.AddViews("permissions", CouchDbPermissionStore.GetViews()).Wait();
            }
        }
示例#2
0
        private void ConfigureApplicationRegistrations(TinyIoCContainer container)
        {
            container.Register(_appConfig);
            container.Register(_loggerFactory);
            container.Register(_logger);
            var options            = new MemoryCacheOptions();
            var eventLogger        = LogFactory.CreateEventLogger(_loggingLevelSwitch, _appConfig);
            var serilogEventWriter = new SerilogEventWriter(eventLogger);

            container.Register <IEventWriter>(serilogEventWriter);
            container.Register(options);
            container.Register <IPropertySettings>(_appConfig.DefaultPropertySettings);
            container.Register(typeof(IOptions <>), typeof(OptionsManager <>));
            container.Register <IMemoryCache, MemoryCache>();
            container.Register <Domain.Defaults.Authorization>();

            var httpClient = new HttpClient();

            container.Register(httpClient);

            container.Register <IPersistenceConfigurator>((c, p) =>
            {
                switch (_appConfig.StorageProvider.ToLowerInvariant())
                {
                case StorageProviders.InMemory:
                    return(new InMemoryConfigurator(_appConfig));

                case StorageProviders.CouchDb:
                    return(new CouchDbConfigurator(_appConfig));

                case StorageProviders.SqlServer:
                    return(new SqlServerConfigurator(_appConfig));

                default:
                    throw new ConfigurationException($"Invalid configuration for StorageProvider: {_appConfig.StorageProvider}. Valid storage providers are: {StorageProviders.InMemory}, {StorageProviders.CouchDb}, {StorageProviders.SqlServer}");
                }
            });

            var configurator = container.Resolve <IPersistenceConfigurator>();

            configurator.ConfigureApplicationInstances(container);
        }