0
HybridHttpOrThreadLocalScoped 수명주기를 사용하여 제네릭 인스턴스가 생성되도록 닫힌 형식을 어떻게 등록합니까?StructureMap의 스캐너를 사용하여 닫힌 형식 등록
내 클래스 :
public interface IBaseService
{
}
public interface IAccountService
{
void Save(Account entry);
Account GetById(string id);
List<Account> GetList();
void Delete(string id);
bool Exists(string id);
}
public interface IClientService
{
void Save(Client entry);
Client GetById(string id);
List<Client> GetList();
void Delete(string id);
bool Exists(string id);
}
public class AccountService : IBaseService, IAccountService
{
Some code for managing accounts
}
public class ClientService : IBaseService, IClientService
{
Some code for managing clients
}
종속성 해결 :
public StructureMapContainer(IContainer container)
{
_container = container;
_container.Configure(x => x.Scan(y =>
{
y.AssembliesFromApplicationBaseDirectory();
y.WithDefaultConventions();
y.LookForRegistries();
y.ConnectImplementationsToTypesClosing(typeof(IService<>))
.OnAddedPluginTypes(t => t.HybridHttpOrThreadLocalScoped());
}));
}
자동으로 IBaseService의 인스턴스를 생성하기위한 해결의 구문은 무엇입니까? ConnectImplementationsToTypesClosing 사용은 열린 제네릭에 대해서만 작동합니다. 리졸버를 사용해야합니까? 유형을 등록하는 더 좋은 방법이 있습니까? 지금은
, 이것은 내가 그들을 등록 amhandling 방법은 다음과 같은
container.Configure(x =>
{
x.For<IClientService>()
.HybridHttpOrThreadLocalScoped()
.Use(new ClientService());
x.For<IEmailAddressService>()
.HybridHttpOrThreadLocalScoped()
.Use(new EmailAddressService());
x.For<IAccountService>()
.HybridHttpOrThreadLocalScoped()
.Use(new AccountService());
});
나는 그것을 시도 할 것이다. 감사! – rboarman