Beispiel #1
0
 public RedisCache(
     DbToRestConfig setting
     )
 {
     _setting    = setting;
     _connection = ConnectionMultiplexer.Connect(setting.RedisConnectionString);
     _database   = _connection.GetDatabase(setting.RedisDatabaseId.HasValue ? Convert.ToInt32(setting.RedisDatabaseId) : 0);
     _options    = ConfigurationOptions.Parse(setting.RedisConnectionString);
 }
Beispiel #2
0
 public DataProvider(
     DbToRestConfig dbToRestConfig,
     ITypeFinder typeFinder,
     ILogService logService
     )
 {
     _dbToRestConfig = dbToRestConfig;
     _typeFinder     = typeFinder;
     _logService     = logService;
     store           = new Lazy <IDocumentStore>(CreateClient);
 }
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, DbToRestConfig config)
        {
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <DataProvider>().As <IDataProvider>().InstancePerLifetimeScope();
            builder.RegisterType <RedisCache>().As <ICache>().SingleInstance();


            builder.RegisterType <DataProvider>().As <IDataProvider>().InstancePerLifetimeScope();

            builder.RegisterGeneric(typeof(DbRepository <>)).As(typeof(IDbRepository <>)).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(CacheRepository <>)).As(typeof(ICacheRepository <>)).InstancePerLifetimeScope();

            builder.Register((c, p) => new LoggerAdapter(LogManager.GetLogger("DbToRest")))
            .As <ILogService>().SingleInstance();

            builder.RegisterType <DbToRestFileProvider>().As <IDbToRestFileProvider>().InstancePerLifetimeScope();
        }
Beispiel #4
0
        /// <summary>
        /// Register dependencies
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="nopConfig">Nop configuration parameters</param>
        protected virtual IServiceProvider RegisterDependencies(IServiceCollection services, ITypeFinder typeFinder, DbToRestConfig nopConfig)
        {
            var containerBuilder = new ContainerBuilder();

            //register engine
            containerBuilder.RegisterInstance(this).As <IEngine>().SingleInstance();

            //register type finder
            containerBuilder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();


            //populate Autofac container builder with the set of registered service descriptors
            containerBuilder.Populate(services);

            //find dependency registrars provided by other assemblies
            var dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>();

            //create and sort instances of dependency registrars
            var instances = dependencyRegistrars
                            .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar))
                            .OrderBy(dependencyRegistrar => dependencyRegistrar.Order);

            //register all provided dependencies
            foreach (var dependencyRegistrar in instances)
            {
                dependencyRegistrar.Register(containerBuilder, typeFinder, nopConfig);
            }

            //create service provider
            _serviceProvider = new AutofacServiceProvider(containerBuilder.Build());

            return(_serviceProvider);
        }
Beispiel #5
0
        /// <summary>
        /// Add and configure services
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration of the application</param>
        /// <param name="nopConfig">Nop configuration parameters</param>
        /// <returns>Service provider</returns>
        public IServiceProvider ConfigureServices(IServiceCollection services, IConfiguration configuration, DbToRestConfig restConfig)
        {
            //find startup configurations provided by other assemblies
            var typeFinder            = new WebAppTypeFinder();
            var startupConfigurations = typeFinder.FindClassesOfType <IDbToRestStartup>();

            //create and sort instances of startup configurations
            var instances = startupConfigurations
                            .Select(startup => (IDbToRestStartup)Activator.CreateInstance(startup))
                            .OrderBy(startup => startup.Order);

            //configure services
            foreach (var instance in instances)
            {
                instance.ConfigureServices(services, configuration);
            }

            //register mapper configurations
            AddAutoMapper(services, typeFinder);

            //register dependencies
            RegisterDependencies(services, typeFinder, restConfig);

            //run startup tasks
            RunStartupTasks(typeFinder);

            //resolve assemblies here. otherwise, plugins can throw an exception when rendering views
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            return(_serviceProvider);
        }