Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="services"></param>
        /// <param name="storeOptionsAction"></param>
        /// <returns></returns>
        public static IServiceCollection AddOperationalDbContext(this IServiceCollection services,
                                                                 Action <OperationalStoreOptions> storeOptionsAction = null)
        {
            var options = new OperationalStoreOptions();

            services.AddSingleton(options);
            storeOptionsAction?.Invoke(options);


            var fsql = new FreeSql.FreeSqlBuilder()
                       .UseConnectionString(options.DataType, options.ConnectionString)
                       .UseAutoSyncStructure(true) //自动同步实体结构到数据库
                       .Build <OperationalDb>();   //请务必定义成 Singleton 单例模式

            fsql.ConfigurePersistedGrantContext();
            fsql.SyncStructurePersistedGrant();

            services.AddSingleton(fsql);
            //TODO  services.AddTransient<TokenCleanupService>();
            return(services);
        }