-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Should we consider sealed the newly introduced attributes for keyed service #90321
Comments
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsWe introduced From the keyed service PR: #87183 code search result:
|
I checked the transcript from the API review and found @benjaminpetit mentioned this was intentional: |
@ericstj thank you very much |
By allowing inheritance on Here is an example: public class CustomKey
{
public CustomKey(int n, string str)
{
N = n;
Str = str;
}
public int N { get; }
public string Str { get; }
}
public sealed class FromServicesWithCustomKey : FromKeyedServicesAttribute
{
public FromServicesWithCustomKey(int n, string str)
: base(new CustomKey(n, str))
{
}
}
public class CustomService
{
private readonly CustomKey _key;
public CustomService([ServiceKey] CustomKey key)
{
_key = key;
}
public int N => _key.N;
public string Str => _key.Str;
}
[Fact]
public void InheritanceTest()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddKeyedTransient<CustomService>(KeyedService.AnyKey);
var provider = CreateServiceProvider(serviceCollection);
var service = provider.GetKeyedService<CustomService>(new CustomKey(12, "hello"));
Assert.Equal(12, service.N);
Assert.Equal("hello", service.Str);
} |
We introduced
ServiceKeyAttribute
andFromKeyedServicesAttribute
for keyed service, while they are not sealed, and there're no inherits from the repo search result, since they're new types introduced, should we consider making them sealed?From the
sealed
proposal #49944, we may prefersealed
for these typeskeyed service PR: #87183
code search result:
https://github.com/search?q=repo%3Adotnet%2Fruntime%20ServiceKeyAttribute&type=code
https://github.com/search?q=repo%3Adotnet%2Fruntime%20FromKeyedServicesAttribute&type=code
The text was updated successfully, but these errors were encountered: