Exemple #1
0
        public static BuiltBuilder AddBuilt(this IServiceCollection services, Action <BuiltOptions> setupAction)
        {
            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction));
            }
            services.Configure(setupAction);

            /*
             * services.Configure<BuiltOptions>(options =>
             * {
             *  options.UseMongodb("");
             * });
             */
            var options = new BuiltOptions();

            setupAction(options);
            services.AddSingleton(options);

            services.AddScoped(typeof(IRepository <>), typeof(Repository <>));
            services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork));
            //使用事物时,表和数据库一定要存在.
            //初始化,IEntity的集合
            return(new BuiltBuilder(services));
        }
Exemple #2
0
 public static BuiltOptions UseMongodb(this BuiltOptions options, MongoUrl url)
 {
     if (url == null)
     {
         throw new ArgumentNullException(nameof(url));
     }
     options.Url = url;
     return(options.UseMongodb(MongoClientSettings.FromUrl(url)));
 }
Exemple #3
0
 public static BuiltOptions UseMongodb(this BuiltOptions options, string connectionString)
 {
     if (string.IsNullOrWhiteSpace(connectionString))
     {
         throw new ArgumentNullException(nameof(connectionString));
     }
     options.ConnectionString = connectionString;
     return(options.UseMongodb(new MongoUrl(connectionString)));
 }
Exemple #4
0
 public static BuiltOptions UseMongodb(this BuiltOptions options, MongoClientSettings configure)
 {
     if (configure == null)
     {
         throw new ArgumentNullException(nameof(configure));
     }
     options.Settings = configure;
     return(options);
 }
Exemple #5
0
 public UnitOfWork(BuiltOptions config)
 {
     DotUseTransaction = config.DotUseTransaction;
     db = new Database(config.Url);
     if (DotUseTransaction)
     {
         return;
     }
     //// 设置隔离级别;
     //StartTransaction(new TransactionOptions(
     //    readConcern: ReadConcern.Snapshot,
     //    writeConcern: WriteConcern.WMajority));
 }