依存関係のインストール中に IoC コンテナーを使用するのは悪い習慣ですか、それともコードの匂いですか?
これは私のコンポジションルートです:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
Assembly modelAssembly = typeof(UserLoginModel).Assembly;
Assembly controllerAssembly = typeof(HomeController).Assembly;
container.Install(
new MvcInfrastructureInstaller(modelAssembly, viewAssembly, controllerAssembly, applicationTitle, resourceAssemblyLocations),
new MiniMembershipInstaller(),
new ServiceInstaller(),
new RepositoryInstaller(),
new LibraryInstaller(),
new AutoMapperProfileInstaller() // this installer needs to resolve dependencies such as repositories through the container itself, so it goes last.
);
}
マッパーAutoMapperProfileInstaller
を初期化するために、依存関係を含むプロファイルを解決する必要があります
public class AutoMapperProfileInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
Profile entityToViewModel = container.Resolve<EntityToViewModelProfile>();
Profile[] profiles = new[] { entityToViewModel };
Mapper.Initialize(config =>
{
config.ConstructServicesUsing(container.Resolve);
foreach (Profile profile in profiles)
{
config.AddProfile(profile);
}
});
}
}
AutoMapper
これは多くのレベルで間違っているように感じます。プロファイルを初期化するより良い方法は何でしょうか?