コード例 #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            var fsql = new MultiFreeSql();

            fsql.Register("db1", () =>
            {
                var db = new FreeSqlBuilder().UseConnectionString(DataType.Sqlite, "data source=db1.db").Build();
                //db.Aop.CommandAfter += ...
                return(db);
            });
            fsql.Register("db2", () =>
            {
                var db = new FreeSqlBuilder().UseConnectionString(DataType.Sqlite, "data source=db2.db").Build();
                //db.Aop.CommandAfter += ...
                return(db);
            });
            fsql.Register("db3", () =>
            {
                var db = new FreeSqlBuilder().UseConnectionString(DataType.Sqlite, "data source=db3.db").Build();
                //db.Aop.CommandAfter += ...
                return(db);
            });

            services.AddSingleton <IFreeSql>(fsql);
            services.AddControllers();
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var fsql = new MultiFreeSql();

            fsql.Register("db1", () =>
            {
                var db = new FreeSqlBuilder()
                         .UseConnectionString(DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root; Initial Catalog=db1;Charset=utf8; SslMode=none;Min pool size=1")
                         .UseMonitorCommand(cmd => Console.WriteLine($"Ị̈߳º{cmd.CommandText}\r\n"))
                         .UseNoneCommandParameter(true)
                         .UseAutoSyncStructure(true)
                         .Build();

                db.GlobalFilter
                .Apply <IDeleted>("test4", r => r.IsDeleted == false);

                return(db);
            }
                          );

            fsql.Register("db2", () =>
            {
                var db = new FreeSqlBuilder()
                         .UseConnectionString(DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root; Initial Catalog=db2;Charset=utf8; SslMode=none;Min pool size=1")
                         .UseAutoSyncStructure(true)
                         .Build();
                return(db);
            }
                          );
            fsql.Register("db3", () =>
            {
                var db = new FreeSqlBuilder()
                         .UseConnectionString(DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root; Initial Catalog=db3;Charset=utf8; SslMode=none;Min pool size=1")
                         .UseAutoSyncStructure(true)
                         .Build();
                return(db);
            }
                          );



            services.AddSingleton <IFreeSql>(fsql);
            services.AddFreeRepository();

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "OvOv.FreeSql.IdleBus", Version = "v1"
                });
            });
        }