Register null as instance in Unity container
In the .RegisterType<IMyRepository, MyRepository>()
call, specify the InjectionConstructor with an OptionalParameter, as in
.RegisterType<IMyRepository, MyRepository>(new InjectionConstructor(
new ResolvedParameter<IDataContext>(),
new OptionalParameter<ICacheProvider>()));
I found that RegisterType, instead of Register instance, supports returning null.
container.RegisterType<IInterface>(new InjectionFactory((c) => null));
This was the most straightforward way of getting an actual null
to be returned.