If i understood the problem correctly (and take in account that it is hard to argue about correct solution without seeing the actual code) the approach would be like this.
Let's assume you have next solution structure:
SharedLib(can be just dll/nuget)
...
AppOne(refs and DI's shared)
...
AppTwo(refs and DI's shared)
...
Then what you'll need to do:
SharedLib
...
Shared.DI (refs SharedLib and package with your IoC container, and other stuff if needed)
...
AppOne (refs Shared.DI)
...
AppTwo (refs Shared.DI)
...
In Shared.DI
you create a method called like RegisterShared
which will handle all registrations and will be called from AppOne
and AppTwo
. I would suggest somth like this:
public static RegistrationExtensions
{
public static void RegisterShared(this YourIoCBuilder builder,
Action<YourIoCBuilder> registerUniqueServiceAction)
{
// do the common stuff
registerUniqueServiceAction(builder);
}
}
You can omit the registerUniqueServiceAction
and register the needed service just before or after but personally I prefer more explicit API so it would be obvious that this method does not register everything needed for the SharedLib
to work. Also depended on what exactly IoC you use you can provide more obvious signature for registerUniqueServiceAction
so it would be clear what actually is needed.