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
publicclassDryExamples{[Fact]// This works ok.publicvoidTransferMultipleThenResolveEnumerable(){varservices=newServiceCollection();services.AddScoped<IPrinter,Printer>();services.AddScoped<IPrinter,PrinterA>();services.AddScoped<IPrinter,PrinterB>();services.AddScoped<IPrinter,NeighborPrinter>();varspf=newDryIocServiceProviderFactory();vardryContainer=spf.CreateBuilder(services);varmsContainer=dryContainer.GetServiceProvider();Assert.Equal(dryContainer.Resolve<IEnumerable<IPrinter>>().Count(),msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count());}[Fact]// I have not been able to get this to work.publicvoidTransferMultipleThenResolveEnumerableFromChild(){varservices=newServiceCollection();services.AddScoped<IPrinter,Printer>();services.AddScoped<IPrinter,PrinterA>();services.AddScoped<IPrinter,PrinterB>();services.AddScoped<IPrinter,NeighborPrinter>();varspf=newDryIocServiceProviderFactory();varrootContainer=spf.CreateBuilder(newServiceCollection());varchildContainer=rootContainer.CreateChild(RegistrySharing.Share,"child-stamp",IfAlreadyRegistered.AppendNewImplementation);//childContainer.Populate(services);foreach(varserviceinservices){childContainer.RegisterDescriptor(service,IfAlreadyRegistered.AppendNewImplementation,"child-stamp");}varmsContainer=childContainer.GetServiceProvider();Assert.Equal(childContainer.Resolve<IEnumerable<IPrinter>>().Count(),msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count());}}privateinterfaceIPrinter{}privateclassPrinter:IPrinter{}privateclassPrinterA:IPrinter{}privateclassPrinterB:IPrinter{}privateclassNeighborPrinter:IPrinter{}
The first test works, and I expect to be able to do similar with a child container. However, the fact that the child container has a default key seems to break this expectation.
childContainer.Populate(services); hard-codes append-if-not-keyed, so I tried calling childContainer.RegisterDescriptor in the loop, but discovered that AppendNewImplementation and AppendNotKeyed are basically not allowed in Regsitry.WithKeyedService(...).
Functionally, I'm looking to move away from a setup with unity container that has child containers. ie child containers can resolve from parent, but cannot interfere with parent registrations. Parent cannot see child services/registrations.
Please let me know if this is achievable.
I will update IssuesTests shortly.
The text was updated successfully, but these errors were encountered:
Yes, in regard to childContainer.RegisterDescriptor(service, IfAlreadyRegistered.AppendNewImplementation, "child-stamp");
The IfAlreadyRegistered.AppendNewImplementation is incompatible with the service key. And yes, it is not great that the fact is not reflected by API.
So you have uncovered (for me too) that using the unique key won't allow the multiple default implementations in the child containers.
I think you may use the registration metadata to achieve this behavior, because it is not supposed to be unique.
But currently there is no simple way to provide such as rules. I will think on it.
Yes. Unfortunately I filed this/these report yesterday when GitHub was having troubles. I got a lot of error responses before one was successful. Seems GitHub reported an error to me even though it posted ok.
The first test works, and I expect to be able to do similar with a child container. However, the fact that the child container has a default key seems to break this expectation.
childContainer.Populate(services);
hard-codes append-if-not-keyed, so I tried callingchildContainer.RegisterDescriptor
in the loop, but discovered thatAppendNewImplementation
andAppendNotKeyed
are basically not allowed inRegsitry.WithKeyedService(...)
.Functionally, I'm looking to move away from a setup with unity container that has child containers. ie child containers can resolve from parent, but cannot interfere with parent registrations. Parent cannot see child services/registrations.
Please let me know if this is achievable.
I will update IssuesTests shortly.
The text was updated successfully, but these errors were encountered: