public static StorageBuilder AddEntityFrameworkCore <TDbContext>(this StorageBuilder storageBuilder, Action <DbContextOptionsBuilder> optionsAction) where TDbContext : StorageContext
 {
     storageBuilder.Services.TryAddTransient <IDbContextProvider <TDbContext>, DefaultDbContextProvider <TDbContext> >();
     storageBuilder.Services.AddDbContext <TDbContext>(optionsAction, ServiceLifetime.Transient, ServiceLifetime.Transient);
     RegisterRepository <TDbContext>(storageBuilder.Services);
     return(storageBuilder);
 }
Example #2
0
 /// <summary>
 ///     Adds MongoDB storage for any unregistered type.
 /// </summary>
 public static StorageBuilder AddMongoAny(this StorageBuilder builder)
 {
     builder.Services
     .ReplaceScoped(typeof(IStorageProvider <>), typeof(MongoStorageProvider <>))
     .ConfigureSerializer(b => b.AddJsonTypeAny());
     return(builder);
 }
Example #3
0
 /// <summary>
 ///     Adds local storage for any unregistered type.
 /// </summary>
 public static StorageBuilder AddHistoricalLocalAny(this StorageBuilder builder)
 {
     builder.Services
     .ReplaceSingleton(typeof(IHistoricalStorageProvider <>), typeof(LocalHistoricalStorageProvider <>))
     .ConfigureSerializer(b => b.AddJsonTypeAny());
     return(builder);
 }
Example #4
0
 /// <summary>
 ///     Adds local partitioned storage for any unregistered type.
 /// </summary>
 public static StorageBuilder AddLocalPartitionedAny(this StorageBuilder builder)
 {
     builder.Services
     .ReplaceSingleton(typeof(IPartitionedStorageProvider <>), typeof(LocalPartitionedStorageProvider <>))
     .ConfigureSerializer(b => b.AddJsonTypeAny());
     return(builder);
 }
Example #5
0
 public void storage_builder()
 {
     IStorage storage = new StorageBuilder()
                        .Register <hello_world>()
                        .Register <Factory>()
                        .Build();
 }
Example #6
0
        public static FightBuilder ConfigureStorage(this FightBuilder fightBuilder, Action <StorageBuilder> setupAction)
        {
            StorageBuilder builder = new StorageBuilder(fightBuilder.Services);

            setupAction?.Invoke(builder);
            builder.Build();
            return(fightBuilder);
        }
Example #7
0
        public void builder_Object_Services_is_not_empty_after_Register()
        {
            StorageBuilder builder = new StorageBuilder();

            exec(builder, typeof(TestClass));

            Assert.IsNotEmpty(builder.Object.Services.GetServices());
        }
Example #8
0
        public void builder_Object_Services_count_is_one()
        {
            StorageBuilder builder = new StorageBuilder();

            exec(builder, typeof(TestClass));

            Assert.IsTrue(builder.Object.Services.GetServices().Count() == 1);
        }
Example #9
0
        public void builder_Object_Services_not_null()
        {
            StorageBuilder builder = new StorageBuilder();

            exec(builder, typeof(TestClass));

            Assert.NotNull(builder.Object.Services);
        }
Example #10
0
        public void builder_Object_is_assignable_to_IStorage()
        {
            StorageBuilder builder = new StorageBuilder();

            exec(builder, typeof(TestClass));

            Assert.IsTrue(builder.Object is IStorage);
        }
Example #11
0
        public void builder_Object_is_instance_of_Storage()
        {
            StorageBuilder builder = new StorageBuilder();

            exec(builder, typeof(TestClass));

            Assert.IsInstanceOf <Storage>(builder.Object);
        }
Example #12
0
 /// <summary>
 ///     Apply a list of configuration instances <paramref name="storageConfigurations" />.
 /// </summary>
 public static StorageBuilder AddConfiguration(this StorageBuilder builder, params IStorageConfiguration[] storageConfigurations)
 {
     foreach (var config in storageConfigurations)
     {
         config.Configure(builder);
     }
     return(builder);
 }
Example #13
0
 /// <summary>
 ///     Configures the storage to connect a MongoDB database.
 /// </summary>
 public static StorageBuilder UseMongo(this StorageBuilder builder, IConfigurationSection configuration)
 {
     builder.Services
     .AddMongoClientFactory()
     .ConfigureMongoOptions(configuration)
     .ConfigureMongoStoringOptions(_ => { });
     return(builder);
 }
Example #14
0
 /// <summary>
 ///     Adds partitioned MongoDB storage for any unregistered type.
 /// </summary>
 public static StorageBuilder AddMongoPartitionedAny(this StorageBuilder builder)
 {
     builder
     .AddMongoHistoricalAny()
     .Services
     .ReplaceScoped(typeof(IPartitionedStorageProvider <>), typeof(MongoPartitionedStorageProvider <>))
     .ConfigureSerializer(b => b.AddJsonTypeAny());
     return(builder);
 }
Example #15
0
        public IDbCommand CreateInsertCommand(IEnumerable <IDicomDataParameter> conditions)
        {
            IDbCommand insertCommand = CreateCommand( );

            StorageBuilder.BuildInsert(conditions, insertCommand);

            SetConnectionIfNull(insertCommand);

            return(insertCommand);
        }
Example #16
0
        /// <summary>
        ///     Adds local partitioned storage of <paramref name="valueType"/> with <paramref name="keyType"/>.
        /// </summary>
        public static StorageBuilder AddLocalPartitioned(this StorageBuilder builder, Type keyType, Type valueType)
        {
            var serviceType        = typeof(IPartitionedStorageProvider <>).MakeGenericType(valueType);
            var implementationType = typeof(LocalPartitionedStorageProvider <>).MakeGenericType(valueType);

            builder.Services
            .ReplaceSingleton(serviceType, implementationType)
            .ConfigureSerializer(b => b.AddJsonType(keyType).AddJsonType(valueType));
            return(builder);
        }
Example #17
0
        public void builder_Object_Services_contains_TestClass()
        {
            Type testClassType = typeof(TestClass);

            StorageBuilder builder = new StorageBuilder();

            exec(builder, testClassType);

            Assert.NotNull(builder.Object.Services.GetServices().FirstOrDefault(x => x.Registration.TargetType == testClassType));
        }
Example #18
0
        public IDbCommand CreateDeleteInstanceCommand(string sopInstanceUID)
        {
            IDbCommand command = CreateCommand( );

            StorageBuilder.BuildDelete(sopInstanceUID, command);

            SetConnectionIfNull(command);

            return(command);
        }
Example #19
0
        /// <summary>
        ///     Adds MongoDB storage of <paramref name="valueType"/> with <paramref name="keyType"/>.
        /// </summary>
        public static StorageBuilder AddMongo(this StorageBuilder builder, Type keyType, Type valueType)
        {
            var serviceType        = typeof(IStorageProvider <>).MakeGenericType(valueType);
            var implementationType = typeof(MongoStorageProvider <>).MakeGenericType(valueType);

            builder.Services
            .ReplaceScoped(serviceType, implementationType)
            .ConfigureSerializer(b => b.AddJsonType(keyType).AddJsonType(valueType));
            return(builder);
        }
Example #20
0
        public void returns_not_null_if_target_was_interface_of_registered_class()
        {
            IStorage storage = new StorageBuilder()
                               .Register <TestClass>()
                               .Build();

            IReadOnlyContainer container = ContainerFactory.ReadOnlyContainer(storage);

            Assert.NotNull(exec <ITestClass>(container));
        }
Example #21
0
        public void returns_instanceof_TestClass_if_target_was_ITestClass()
        {
            IStorage storage = new StorageBuilder()
                               .Register <TestClass>()
                               .Build();

            IReadOnlyContainer container = ContainerFactory.ReadOnlyContainer(storage);

            Assert.IsInstanceOf <TestClass>(exec <ITestClass>(container));
        }
Example #22
0
        /// <summary>
        /// Default constructor
        /// </summary>
        private UserWrapper()
        {
            AuthBuilder authBuilder = AuthBuilder.GetInstance();

            this.IUserMgr     = authBuilder.GetManager <IUserMgr>(AuthBuilder.IUSERMGR);
            this.IUserRoleMgr = authBuilder.GetManager <IUserRoleMgr>(AuthBuilder.IUSERROLEMGR);
            StorageBuilder storageBuilder = StorageBuilder.GetInstance();

            this.IStorageBlobMgr = storageBuilder.GetManager <IStorageBlobMgr>(StorageBuilder.ISTORAGEBLOBMGR);
            this.EmailWrapper    = EmailWrapper.GetInstance();
        }
Example #23
0
        public void another_test()
        {
            IStorage storage = new StorageBuilder()
                               .Register <Tobi>()
                               .Register <IFlorka>()
                               .Build();

            IContainer container = ContainerFactory.Container(storage);

            Florka florka = container.Resolve <Florka>();
        }
Example #24
0
        public ContainerTests()
        {
            _container = new Container(_ =>
            {
                _.IncludeRegistry <CrispinRestRegistry>();
                _.IncludeRegistry <MediatrRegistry>();

                _.For(typeof(ILogger <>)).Use(typeof(FakeLogger <>));
                _.For <IStorage>().Use(StorageBuilder.Configure(new InMemoryStorage()));
            });
        }
Example #25
0
        private static void InjectStrongConfiguration(WebHostBuilderContext host, IServiceCollection services)
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json")
                          .AddJsonFile($"appsettings.{host.HostingEnvironment.EnvironmentName}.json", optional: true)
                          .Build();

            var config = builder.Get <CrispinConfiguration>() ?? new CrispinConfiguration();

            services.AddSingleton(StorageBuilder.Build(config));
            services.AddSingleton(config);
        }
        public RoleTestBase()
        {
            //Context = StorageBuilder.GetContext();
            //UnitOfWork = (UnitOfWork)StorageBuilder.GetUnitOfWork(Context);
            InMemoryDatabaseContext = StorageBuilder.GetInMemContextUserAndRoleData();
            UnitOfWork = (UnitOfWork)StorageBuilder.GetUnitOfWork(InMemoryDatabaseContext);
            var configuration = new MapperConfiguration(cfg => cfg.AddProfile <IdentityEntitiesToModelsMappingProfile>());
            //var configuration = new MapperConfiguration(cfg => new IdentityEntitiesToModelsMappingProfile());
            var mapper = configuration.CreateMapper();

            RoleStore = new RoleStore(UnitOfWork, mapper);
        }
Example #27
0
        public void dont_throws_if_target_was_registered_with_instance()
        {
            TestClass test = new TestClass();

            IStorage storage = new StorageBuilder()
                               .RegisterObject(test)
                               .Build();

            IReadOnlyContainer container = ContainerFactory.ReadOnlyContainer(storage);

            Assert.DoesNotThrow(() => exec <TestClass>(container));
        }
Example #28
0
        public void returns_same_instances_if_target_was_registered_with_instance()
        {
            TestClass test = new TestClass();

            IStorage storage = new StorageBuilder()
                               .RegisterObject(test)
                               .Build();

            IReadOnlyContainer container = ContainerFactory.ReadOnlyContainer(storage);

            Assert.AreEqual(test, exec <TestClass>(container));
        }
        /// <summary>
        /// 添加存储服务
        /// </summary>
        /// <param name="services"><see cref="IServiceCollection"/></param>
        /// <param name="builer"><see cref="StorageBuilder"/> 配置</param>
        /// <param name="storageName">Storage的名称</param>
        /// <returns></returns>
        public static IServiceCollection AddEFStorage(this IServiceCollection services, Action <IStorageBuilder> builer, string storageName = GrainStorage.DefaultName)
        {
            //配置差异对比服务
            services.TryAddSingleton <IEntityChangeDetector, EntityChangeDetector>();
            services.TryAddSingleton <IEntityChangeManagerFactory, EntityChangeManagerFactory>();

            //配置Orleans 的存储配置
            services.AddTransientNamedService <IGrainStorage, GrainStorage>(storageName);

            //对应实体的仓储配置
            var builder = new StorageBuilder(services);

            builer.Invoke(builder);
            return(services);
        }
        /// <summary>
        /// Configures the storage which required by Parbad for saving and loading data.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configureStorage"></param>
        public static IParbadBuilder ConfigureStorage(this IParbadBuilder builder, Action <IStorageBuilder> configureStorage)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configureStorage == null)
            {
                throw new ArgumentNullException(nameof(configureStorage));
            }

            var storageBuilder = new StorageBuilder(builder.Services);

            configureStorage(storageBuilder);

            return(builder);
        }