5
종속성을 설치하는 동안 IoC 컨테이너를 사용하는 것이 좋지 않습니까?종속성을 설치하는 동안 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
프로파일을 초기화하는 더 좋은 방법은?