次のコンストラクタがあります。
public ReferenceService(
IAzureTable<Reference> referenceRepository)
{
_referenceRepository = referenceRepository;
}
public ReferenceService(CloudStorageAccount devStorageAccount)
{
_referenceRepository = new AzureTable<Reference>(devStorageAccount, "TestReferences");
}
そしてBootstrapper.csで
CloudStorageAccount storageAccount;
storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
var container = new UnityContainer();
container.RegisterType<IReferenceService, ReferenceService>();
Unity にサービスを解決させようとすると、1 つのパラメーターを持つ複数のコンストラクターがあるというエラー メッセージが表示されます。
[ResolutionFailedException: Resolution of the dependency failed, type = "WebUx.xController", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type ReferenceService has multiple constructors of length 1. Unable to disambiguate.
-----------------------------------------------
At the time of the exception, the container was:
Resolving WebUx.xController,(none)
Resolving parameter "referenceService" of constructor WebUx.xController(
Storage.Services.IContentService contentService,
Storage.Services.IReferenceService referenceService
)
Resolving Storage.Services.ReferenceService,(none) (mapped from Storage.Services.IReferenceService, (none))
]
Unity に 2 つのコンストラクターのいずれかを強制的に使用させる方法はありますか?