क्या निर्भरता स्थापित करते समय आईओसी कंटेनर का उपयोग करने के लिए यह एक खराब अभ्यास या कोड गंध है?क्या निर्भरता स्थापित करते समय आईओसी कंटेनर का उपयोग करने के लिए यह एक खराब अभ्यास या कोड गंध है?
यह मेरी रचना जड़ है:
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
प्रोफाइल शुरू करने का एक बेहतर तरीका?