Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gmiserez opened this issue Oct 16, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@gmiserez
Copy link
Collaborator

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));
@gmiserez gmiserez added the enhancement New feature or request label Oct 16, 2020
@glucaci
Copy link
Member

glucaci commented Oct 19, 2020

We can keep the old implementation and add an overload to don't introduce a braking change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants