One instance for various service types in Microsoft Extensions DI
Recently moving away from Autofac to Microsoft Extensions DI I’ve faced a problem
that there is no API to register one service implementation instance (singleton, scoped) for various service types.
Microsoft DI behaviour
Achieving similar behaviour on Microsoft DI
Autofac allows multiple keys for the same implementation.
Microsoft DI is one to one map.
To achieve the same behaviour choose the type you will use as the primary key (Service in the example below).
For all other types (like IService in the example below) register resolvers that would resolve a service using primary key.