Injectio icon indicating copy to clipboard operation
Injectio copied to clipboard

Abylity to Register keyed service with AnyKey

Open dmitry-bym opened this issue 1 year ago • 1 comments

So its not able to use this cause it's not const. I'm a little confused that the dotnet team decided to use a non-constant value for the key, maybe cause boxing - who knows

[RegisterSingleton(ServiceKey = KeyedService.AnyKey)]

Maybe its possible just to create an enum, and then handle it while source gen, kind of this

public enum ServiceKey { AnyKey }
[RegisterSingleton(ServiceKey = ServiceKey.AnyKey)]

dmitry-bym avatar Mar 22 '24 06:03 dmitry-bym

Thought for a while, it's not good to have two members for same stuff ServiceKey.AnyKey and KeyedService.AnyKey will create confusion, maybe better just add simple flag IsAnyKey, default = false, if true it ignores ServiceKey

dmitry-bym avatar Mar 22 '24 06:03 dmitry-bym