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

Updated Registration doesn't affect located service #310

Open
dansiegel opened this issue Sep 23, 2023 · 0 comments
Open

Updated Registration doesn't affect located service #310

dansiegel opened this issue Sep 23, 2023 · 0 comments

Comments

@dansiegel
Copy link

Description

Typically you would expect that the last registration for a given service would result in that implementation type being the type that will be resolved. This occurs given the following test:

container.Configure(c => c.Export(typeof(IServiceA)).As(typeof(ServiceA1)));
container.Configure(c => c.Export(typeof(IServiceA)).As(typeof(ServiceA2)));
var instance = container.Locate(typeof(IServiceA));
Assert.IsType<ServiceA2>(instance);

However if you first locate the type and then modify the registrations the initial registration is cached and the new registration does not take effect.

container.Configure(c => c.Export(typeof(IServiceA)).As(typeof(ServiceA1)));
var instance = container.Locate(typeof(IServiceA));
Assert.IsType<ServiceA1>(instance);

// Update the container
container.Configure(c => c.Export(typeof(IServiceA)).As(typeof(ServiceA2)));
instance = container.Locate(typeof(IServiceA));
Assert.IsType<ServiceA2>(instance); // Fails because it resolved ServiceA1
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

1 participant