Skip to content

BewitRegistrationBuilder.GetRepository should be of Type Func<IServiceProvider, INonceRepository> to facilitate the use of registered services #5

@gmiserez

Description

@gmiserez

Is your feature request related to a problem? Please describe.
Currently, the property BewitRegistrationBuilder.GetRepository is of type Func<INonceRepository>. This comes with certain limitations, as it is therefore not easily possible to consume services from the serviceProvider during the initialization of the NonceRepository.

Example from the MongoDB persistence package:

        public static BewitRegistrationBuilder UseMongoPersistance(
            this BewitRegistrationBuilder builder,
            BewitMongoOptions options)
        {
            ...
            var client =
                new MongoClient(options.ConnectionString);
            IMongoDatabase db =
                client.GetDatabase(options.DatabaseName);

            builder.GetRepository = () => new NonceRepository(
                db, options.CollectionName ?? nameof(Token));

            return builder;
        }

Describe the solution you'd like
BewitRegistrationBuilder.GetRepository should be of type Func<IServiceProvider, INonceRepository>. That way we could use registered services to initialize the NonceRepository:

builder.GetRepository = (ctx) => new NonceRepository(
                ctx.GetRequiredService<IMongoDatabase>(), options.CollectionName ?? nameof(Token));

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions