-
-
Notifications
You must be signed in to change notification settings - Fork 837
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
No way to get scopes tags list for MatchingScopeLifetime #730
Comments
Will have to think about this one. Keep in mind there are things like registration sources that dynamically generate registrations. I worry about solutions or features that rely on iterating through the registrations collection. On the other hand, I could potentially see something where you may query about information for a specific registration. Hmmm. |
Reading over these now that we've come up for air a bit from the .NET Core RTM, I think if we can address #567 - the ability for AutoActivate/IStartable to work in nested lifetime scopes - that may be the best we can do. We don't actually figure out what the Saying something like, "auto-activate everything that was registered just for this matching scope at the time the scope is created" is sort of edge case from an IoC perspective. One thing you could do to work around the issue is to use events and metadata. First, when registering things, add metadata to the things you want to auto-activate. builder.RegisterType<MyComponent>()
.As<IService>()
.InstancePerMatchingLifetimeScope("child")
.WithMetadata("scope", "child"); Then attach to the container private static void Activate(IEnumerable<Meta<Lazy<IService>>> services)
{
foreach(var meta in services)
{
if(meta["scope"].Equals("child"))
{
// The value of Meta<Lazy<T>> is Lazy<T>
// The value of Lazy<T> is the resolved instance
meta.Value.Value.DoActivate();
}
}
}
var container = builder.Build();
// Handle the child scope beginning event to activate everything.
container.ChildLifetimeScopeBeginning += (sender, args) =>
Activate(args.LifetimeScope.Resolve<IEnumerable<Meta<Lazy<IService>>>>());
using(var scope = container.BeginLifetimeScope("child"))
{
// The named lifetime scope will kick off the event handler.
} (Note I wrote that stuff off the top of my head. You may have to tweak it a bit, add error handling, etc.) Working around it with events seems like more effort, but it means a couple of things:
Something we could add, though, would be a "well known" metadata item on every registration that's registered using |
I added an extension method on |
I want to be able to get scopes tags from
InstancePerMatchingLifetimeScope
when iterating throughComponentRegistry.Registrations
. E.g. I want to activate everything registered forApplication
scope but I can't access scopes for components.Please add this.
The text was updated successfully, but these errors were encountered: