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

Registering modules as Singleton is causing problems #279

Closed
enriquein opened this issue Sep 30, 2021 · 3 comments
Closed

Registering modules as Singleton is causing problems #279

enriquein opened this issue Sep 30, 2021 · 3 comments

Comments

@enriquein
Copy link

I'm currently trying to upgrade a web app to use .Net 6 and the pre-release version of Carter. Upgrading was pretty much painless, and the new API is pretty cool, however the changes to module DI registration introduced in 632c7c7 are causing me startup problems when a ICarterModule instance needs to request a scoped dependency.

The error I get is:

Unhandled exception. System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Carter.ICarterModule Lifetime: Singleton ImplementationType: MyServer.Modules.MyModule': Cannot consume scoped service 'MyServer.SomeScopedService' from singleton 'Carter.ICarterModule'.)

Is the idea now that all dependencies will need to be specified as part of the function that handles the request (ie: the RequestDelegate) instead of the module constructor? Or did I just miss an alternate way to register my modules for my use-case?

I guess as as workaround I can just skip calling AddCarter and register my modules, validators, and response negotiators by hand. But would be very helpful to know the official stance on this.

Thanks!

@jchannon
Copy link
Member

jchannon commented Sep 30, 2021 via email

@enriquein
Copy link
Author

Looking at the new APIs I was afraid this was going to be the answer. Thanks for clarifying!

@jchannon
Copy link
Member

jchannon commented Sep 30, 2021 via email

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

No branches or pull requests

2 participants