IRegistrationSource
for them that is updated after build with additional known concrete types before they are resolved.
@markelli The constructor of MyViewModel
is not creating the ILifetimeScope
instance, it is receiving a reference to the ILifetimeScope
that it is being created in. Because the view model did not create the lifetime scope it should not be disposing it. The lifetime scope should be disposed by the thing that created it.
I would recommend having a read of this blog post from Nick to get a better understanding of lifetime scopes. It written some time ago but remains entirely relevant.
@alexmg If I'm creating that MyViewModel
via autofac though then the only object that by default knows about that instance of ILifetimeScope
would be the MyViewModel
no? So where else would I dispose of it?
In this specific case I have another object like MyFirstViewModel
which has a call to scope in it to scope.Resolve<MyViewModel>()
but the only way it would know about the scope created for MyViewModel
is if that were then exposed as a property or something of that nature.
scope
you referred to in MyFirstViewModel
a new child lifetime scope? If it is not and MyViewModel
is resolved from the root lifetime scope disposing it would not be a good thing. You might need to provide some more example code so we can better understand your scenario.
Hey @wasabii
Obviously, I'd prefer you to take all my code and incorporate it, instead of maintaining my own version. But I'm doing things quite differently.
We have too many packages already and need to start offloading some if anything. Do you still require the functionality provided in your package? It is quite different and seems like you might be continually fighting battles on multiple fronts.
Any hope of supporting ByRef ctor parameters? Clarity: I mean for 'in' parameters.
Looks like there is already a related issue open for that. #1226
I have a real question. Imagine I have a set of services. They all depend on each other by resolving each other through interfaces. There's a set of HostedServices that go along with them as well.
I want to register this block of services twice. But have each block only resolve from amongst itself. So, two copies of this set of services, that only depend on other services within the same set. Named services are the idea. Except, I want to make the names of the ctor injectors dynamic to the name of the set, also.
Or, register it all twice, in two separate Lifetime Scopes. However, it's not really a lifetime scope. Because there's HostedServices, and those really need to be started by the top-level generic Host.
var registry = (HttpClientMappingRegistry)builder.Services.Single(sd => sd.ServiceType == typeof(HttpClientMappingRegistry)).ImplementationInstance;
Debug.Assert(registry != null);