StructMap 등록자 생성자에서 (다른 레지스트리에 등록 된) 일부 유형의 인스턴스를 얻으려면 어떻게해야합니까?StructureMap 등록자 생성자에서 인스턴스를 가져 오는 방법은 무엇입니까?
public RepositoriesRegistry()
{
IApplicationSettings lApplicationSettings =
ObjectFactory.GetInstance<IApplicationSettings>();
Debug.Assert(lApplicationSettings != null);
const string cSupportedDevicesConnectionString =
"metadata=res://*/Models.SupportedDevices.Database.SupportedDevicesModel.csdl|res://*/Models.SupportedDevices.Database.SupportedDevicesModel.ssdl|res://*/Models.SupportedDevices.Database.SupportedDevicesModel.msl;provider=System.Data.SqlClient;provider connection string=\"{0}\"";
string lSupportedDevicesConnectionString =
string.Format(cSupportedDevicesConnectionString, lDatabaseConnectionString);
SupportedDevicesEntities lSupportedDevicesEntities =
new SupportedDevicesEntities(lSupportedDevicesConnectionString);
ForRequestedType<SupportedDevicesEntities>().TheDefault.IsThis(
lSupportedDevicesEntities);
ForRequestedType<ISupportedDevicesRepository>().TheDefault.IsThis(
new SupportedDevicesRepository(lSupportedDevicesEntities));
}
IApplicationSettings이 응용 프로그램 설정에 대한 인터페이스입니다 : 나는 그런 코드를 사용하고 싶습니다.
public ApplicationServicesRegistry()
{
ForRequestedType<IApplicationSettings>().TheDefault.IsThis(
new ConfigFileApplicationSettings());
}
그리고 두 레지스트리는 부트 스트 래퍼에 등록 :이 인터페이스 (현재 ConfigFileApplicationSettings 클래스)를 구현하는 구체적인 유형은 다음과 같이 다른 레지스트리에 등록되어 내가의 인스턴스를 얻으려고
#region IBootstrapper Members
public void BootstrapStructureMap()
{
ObjectFactory.Initialize(InitalizeStructureMapContainer);
}
#endregion
#region Private properties
private static bool HasStarted { get; set; }
#endregion
#region Private methods
private void InitalizeStructureMapContainer(IInitializationExpression x)
{
x.IgnoreStructureMapConfig = true;
x.AddRegistry<ViewModelRegistry>();
x.AddRegistry<ApplicationServicesRegistry>();
x.AddRegistry<RepositoriesRegistry>();
x.AddRegistry<DataOperationsRegistry>();
}
#endregion
IApplicationRegisty in registry constructor 오류가 발생했습니다. 나는 StructMap을 올바른 방법으로 사용하는 방법을 철저히 이해하지 못합니다. 나는 그 일을 다른 방식으로해야 할 수도 있습니다. 그러나 어쨌든 어떤 유형의 인스턴스를 Registry 생성자에 일찍 등록 할 수 있습니까?