Exemple #1
0
        /// <summary>
        /// Registers the MongoDB stores services in the DI container and
        /// configures OpenIddict to use the MongoDB entities by default.
        /// </summary>
        /// <param name="builder">The services builder used by OpenIddict to register new services.</param>
        /// <remarks>This extension can be safely called multiple times.</remarks>
        /// <returns>The <see cref="OpenIddictMongoDbBuilder"/>.</returns>
        public static OpenIddictMongoDbBuilder UseMongoDb(this OpenIddictCoreBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            // Note: Mongo uses simple binary comparison checks by default so the additional
            // query filtering applied by the default OpenIddict managers can be safely disabled.
            builder.DisableAdditionalFiltering();

            builder.SetDefaultApplicationEntity <OpenIddictMongoDbApplication>()
            .SetDefaultAuthorizationEntity <OpenIddictMongoDbAuthorization>()
            .SetDefaultScopeEntity <OpenIddictMongoDbScope>()
            .SetDefaultTokenEntity <OpenIddictMongoDbToken>();

            // Note: the Mongo stores/resolvers don't depend on scoped/transient services and thus
            // can be safely registered as singleton services and shared/reused across requests.
            builder.ReplaceApplicationStoreResolver <OpenIddictMongoDbApplicationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceAuthorizationStoreResolver <OpenIddictMongoDbAuthorizationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceScopeStoreResolver <OpenIddictMongoDbScopeStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceTokenStoreResolver <OpenIddictMongoDbTokenStoreResolver>(ServiceLifetime.Singleton);

            builder.Services.TryAddSingleton(typeof(OpenIddictMongoDbApplicationStore <>));
            builder.Services.TryAddSingleton(typeof(OpenIddictMongoDbAuthorizationStore <>));
            builder.Services.TryAddSingleton(typeof(OpenIddictMongoDbScopeStore <>));
            builder.Services.TryAddSingleton(typeof(OpenIddictMongoDbTokenStore <>));

            builder.Services.TryAddSingleton <IOpenIddictMongoDbContext, OpenIddictMongoDbContext>();

            return(new OpenIddictMongoDbBuilder(builder.Services));
        }
        /// <summary>
        /// Registers the MongoDB stores services in the DI container and
        /// configures OpenIddict to use the MongoDB entities by default.
        /// </summary>
        /// <param name="builder">The services builder used by OpenIddict to register new services.</param>
        /// <remarks>This extension can be safely called multiple times.</remarks>
        /// <returns>The <see cref="CouchDbOpenIddictBuilder"/>.</returns>
        public static CouchDbOpenIddictBuilder UseCouchDb(this OpenIddictCoreBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));

            // Note: Mongo uses simple binary comparison checks by default so the additional
            // query filtering applied by the default OpenIddict managers can be safely disabled.
            builder.DisableAdditionalFiltering();

            builder.SetDefaultApplicationEntity <CouchDbOpenIddictApplication>()
            .SetDefaultAuthorizationEntity <CouchDbOpenIddictAuthorization>()
            .SetDefaultScopeEntity <CouchDbOpenIddictScope>()
            .SetDefaultTokenEntity <CouchDbOpenIddictToken>();

            // Note: the Mongo stores/resolvers don't depend on scoped/transient services and thus
            // can be safely registered as singleton services and shared/reused across requests.
            builder.ReplaceApplicationStoreResolver <CouchDOpenIddictbApplicationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceAuthorizationStoreResolver <CouchDOpenIddictbAuthorizationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceScopeStoreResolver <CouchDbOpenIddictScopeStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceTokenStoreResolver <CouchDbOpenIddictTokenStoreResolver>(ServiceLifetime.Singleton);

            builder.Services.TryAddSingleton(typeof(CouchDbOpenIddictApplicationStore <>));
            builder.Services.TryAddSingleton(typeof(CouchDbOpenIddictAuthorizationStore <>));
            builder.Services.TryAddSingleton(typeof(CouchDbOpenIddictScopeStore <>));
            builder.Services.TryAddSingleton(typeof(CouchDbOpenIddictTokenStore <>));

            return(new CouchDbOpenIddictBuilder(builder.Services));
        }