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