private static void ConfigureMarten(IIdentityServerBuilder builder, MartenOptions options)
        {
            var store = DocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = options.SchemaName;
                _.Connection(options.ConnectionString);
            });

            builder.Services.AddSingleton <IDocumentStore>(store);
            builder.Services.AddTransient(_ => store.LightweightSession());
        }
        /// <summary>
        /// Registers the IdentityServer stores with the container
        /// If the <paramref name="connectionString"> is passed , a <see name="IDocumentStore"> and <see name="IDocumentSession"> are registered
        /// </summary>
        /// <param name="builder">IIdentityServerBuilder</param>
        /// <param name="options">MartenOptions</param>
        /// <returns></returns>
        public static IIdentityServerBuilder AddConfigurationStore(
            this IIdentityServerBuilder builder, MartenOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            builder.Services.AddTransient <IClientStore, ClientStore>();
            builder.Services.AddTransient <IResourceStore, ResourceStore>();
            builder.Services.AddTransient <ICorsPolicyService, CorsPolicyService>();
            ConfigureMarten(builder, options);
            return(builder);
        }
        public static IIdentityServerBuilder AddOperationalStore(this IIdentityServerBuilder builder, MartenOptions options, Action <TokenCleanupOptions> tokenCleanUpOptions = null)
        {
            builder.Services.AddScoped <IPersistedGrantStore, PersistedGrantStore>();
            var tokenCleanupOptions = new TokenCleanupOptions();

            tokenCleanUpOptions?.Invoke(tokenCleanupOptions);
            builder.Services.AddSingleton(tokenCleanupOptions);
            builder.Services.AddSingleton <TokenCleanup>();
            ConfigureMarten(builder, options);
            return(builder);
        }