Có phải là một thực tế xấu hoặc có mùi mã để sử dụng một thùng chứa IoC trong khi cài đặt các phụ thuộc không?Có phải là một thực tế xấu hoặc có mùi mã để sử dụng một thùng chứa IoC trong khi cài đặt các phụ thuộc không?
Đây là gốc thành phần của tôi:
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
nhu cầu của tôi để giải quyết một hồ sơ, trong đó có phụ thuộc để khởi tạo các mapper
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);
}
});
}
}
này cảm thấy sai lầm trên nhiều cấp độ, điều gì sẽ cách tốt hơn để khởi tạo AutoMapper
tiểu sử?