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
Hi,
I've been playing around with the new named services feature and thought it could useful for resolving relative URIs into absolute URIs.
Before named services this would have been difficult to achieve since having a Uri depend on another Uri understandably causes a cyclic dependency.
However, now that a specific registration can be injected by name this seems like this should be possible but still causes the cyclic dependency. Is this by design?
[ServiceProvider][Singleton<Uri>(Factory ="BaseUriFactory", Name ="Base")][Singleton<Uri>(Factory ="FullUriFactory", Name ="Full")]internalpartialclassServices{static Uri BaseUriFactory()=>new(@"C:\");static Uri FullUriFactory([FromNamedServices("Base")]UribaseUri){UrirelativeUri=new(@"Test\", UriKind.Relative);returnnew(baseUri, relativeUri);}}
As a workaround I've found I can just inject IServiceProvider for a runtime resolution which is still pretty useful.
static Uri FullUriFactory(IServiceProviderserviceProvider){UribaseUri= serviceProvider.GetRequiredKeyedService<Uri>("Base");UrirelativeUri=new(@"Test\", UriKind.Relative);returnnew(baseUri, relativeUri);}
The text was updated successfully, but these errors were encountered:
Hi,
I've been playing around with the new named services feature and thought it could useful for resolving relative URIs into absolute URIs.
Before named services this would have been difficult to achieve since having a Uri depend on another Uri understandably causes a cyclic dependency.
However, now that a specific registration can be injected by name this seems like this should be possible but still causes the cyclic dependency. Is this by design?
I've recreated a basic repro. Please see attached.
JabNamedServices.zip
As a workaround I've found I can just inject IServiceProvider for a runtime resolution which is still pretty useful.
The text was updated successfully, but these errors were encountered: