You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create configuration provider (e.x TimeProvider in this linked repository) that reloads IConfiguration when configuration source changes.
Use that provider through ConfigureAppConfiguration
Add Convey to application in ConfigureServices. services.AddConvey() is enough to trigger the error.
After executing those steps all configuration providers are going to stop reporting configuration changes.
Workaround
You can create simple service class that requires IConfiguration which is going to be reloaded when you manually detect a moment when it should be reloaded.
Example code:
varconfiguration= configuration as ConfigurationRoot;// (...)
configuration.Reload();
Where the issue originates
Issue resides inside Extensions.cs:GetOptions. Every time when Convey wants to get options from service collection it builds new service provider based on service collection from main application and retrieves IConfiguration to fetch options values.
By using word using on ServiceProvider Convey ensures it is going to be disposed along with objects it created. This is going to dispose IConfiguration object which is ConfigurationRoot under the hood. ConfigurationRoot is going to dispose all configuration providers attached to it which is going to break reloadable functionality.
Proposed solutions
Stop building service provider from service collection provided by users. It can have unintended side effects that are very hard to diagnose.
Instead supply your convey builder with IConfiguration instance in addition to ServiceCollection. IConfiguration should be easily accessible from every Startup.cs. Therefore all existing users should be able to modify their code with ease to cope with this change.
Unfortunately it is going to be a breaking change :/.
Additionally this approach would require an inner instance of ServiceCollection to instantiate your objects during configuring process. All configured objects could be added to main application's ServiceCollection that was provided to Convey. (Personally I think this should be reworked as it looks weird to constantly build and dispose service providers. This is my own opinion though)
This is an approach that is going to eliminate all possible side effects of using ServiceCollection you do not own.
Supply ConveyBuilder with IConfiguration and rewrite method Extensions.cs:GetOptions to use it. There might be other methods that needs to be rewritten to use this approach
The text was updated successfully, but these errors were encountered:
Any update on this?
For me this is a bug that is blocking me from introducing Convey to my projects. It is just going to do haywire in at least Configuration objects.
Apologies for the delayed response - I will take a look into this, e.g. if the IConfiguration could be passed to the ConveyBuilder and used internally within the other components' extension methods. Otherwise, I'd need to introduce some breaking changes, which, hopefully, could be avoided.
Fixed in the latest release - when calling AddConvey() an optional IConfiguration instance can be passed - if it's null, then the default behaviour (building with IServiceProvider) will be used.
Repository with reproducible example
https://github.com/shoter/Convey-Configuration-Error
How to reproduce the problem
TimeProvider
in this linked repository) that reloadsIConfiguration
when configuration source changes.ConfigureAppConfiguration
ConfigureServices
.services.AddConvey()
is enough to trigger the error.After executing those steps all configuration providers are going to stop reporting configuration changes.
Workaround
You can create simple service class that requires
IConfiguration
which is going to be reloaded when you manually detect a moment when it should be reloaded.Example code:
Where the issue originates
Issue resides inside Extensions.cs:GetOptions. Every time when Convey wants to get options from service collection it builds new service provider based on service collection from main application and retrieves
IConfiguration
to fetch options values.By using word using on
ServiceProvider
Convey ensures it is going to be disposed along with objects it created. This is going to disposeIConfiguration
object which isConfigurationRoot
under the hood.ConfigurationRoot
is going to dispose all configuration providers attached to it which is going to break reloadable functionality.Proposed solutions
Instead supply your convey builder with
IConfiguration
instance in addition toServiceCollection
.IConfiguration
should be easily accessible from everyStartup.cs
. Therefore all existing users should be able to modify their code with ease to cope with this change.Unfortunately it is going to be a breaking change :/.
Additionally this approach would require an inner instance of
ServiceCollection
to instantiate your objects during configuring process. All configured objects could be added to main application'sServiceCollection
that was provided to Convey. (Personally I think this should be reworked as it looks weird to constantly build and dispose service providers. This is my own opinion though)This is an approach that is going to eliminate all possible side effects of using
ServiceCollection
you do not own.IConfiguration
and rewrite method Extensions.cs:GetOptions to use it. There might be other methods that needs to be rewritten to use this approachThe text was updated successfully, but these errors were encountered: