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

Allow users to provide a IDocumentStore resolved from an externally managed container #445

Closed
andreasohlund opened this issue Oct 31, 2019 · 0 comments · Fixed by #451
Closed
Labels
Milestone

Comments

@andreasohlund
Copy link
Member

@andreasohlund andreasohlund commented Oct 31, 2019

We currently allow users to pass a custom IDocumentStore via .SetDefaultDocumentStore(func) unfortunately, this assumes that the user have access to an API that allows them to resolve from the container. In MS Dependency injection scenarios this is not the case.

Take the following scenario where a user registers a raven document store in DI and want us to use the same. Since we don't give them a way to resolve from DI they have to hack it via services.BuildServiceProvider() which is considered obsoleted by MS.


public void ConfigureServices(IServiceCollection services)
{
    services.AddRavenDB();

    var endpointConfiguration= new EndpointConfiguration("sales");

    endpointConfiguration.UsePersistence<RavenDBPersistence>()
      .SetDefaultDocumentStore(_ => services.BuildServiceProvider()
          .GetRequiredService<IDocumentStore>());

    
    services.AddNServiceBus(endpointConfiguration);
}

To avoid this we can either:

  1. Look for an IDocumentStore in the container and use it automatically requiring no specific config. This seems to be the pattern that MS is promoting for similar things like IHttpClient, ITelemetryClient etc
  2. Give users a new SetDefaultDocumentStore overload with builder access: .SetDefaultDocumentStore(builder=>builder.Build<IDocumentStore>());

Side note this also relies on #444 getting fixed so that we don't invoke the func to early.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.