オプションの依存関係を持つリポジトリクラスがあります:
class MyRepository : BaseRepository, IMyRepository
{
public MyRepository(IDataContext dataContext, ICacheProvider cacheProvider = null)
: base(dataContext, cacheProvider)
{}
// …
}
cacheProviderパラメーターの存在は、リポジトリーの戦略として機能します。Unityコンテナを次のようにセットアップしたい:
Container.RegisterType<IDataContext, MyDataContext>(new PerResolveLifetimeManager(), new InjectionConstructor())
.RegisterInstance<ICacheProvider>(null) // ???
.RegisterType<IMyRepository, MyRepository>();
つまり、MyRepositoryの1つのパラメーターを持つ特定のInjectionConstructorを指摘するのではなく、cacheProviderパラメーターとしてnullを持つデフォルトのコンストラクターを使用します。
これを行う方法はありますか?