Closed coredevsushant closed 5 years ago
I have Core in which Interface is declared as
public interface IRequestProvider { int SomeId { get; set; } }
Implementation also define in same layer
and then I have another layer Repo layer in which I am calling another external nuget packages called DataAccess layer
in which I have declared
public interface IRequestProvider { int SomeId { get; set; } int SomeOtherId { get; set; } }
so In core and DataAccess both layer I have defined IRequestProvider
Lamar code
public static class SomeRegistry { public static void RegisterDISome(this ServiceRegistry services, IConfigurationRoot configurationRoot) { services.For<IRequestProvider>().Use<RequestProvider>().Scoped(); services.For<DataAccessInterfaces.IRequestProvider>().Use<DataAccessModel.RequestProvider>().Scoped(); } }
Scoped use to pass the same instance throughout the request
Automapper is enable
public class DomainToRepoMappingsProfile : Profile { public DomainToRepoMappingsProfile() { this.CreateMap<IRequestProvider, DataAccess.IRequestProvider>() .ForMember(dst => dst.SomeOtherId, opt => opt.Ignore()); } }
My expectation is when I change something in Core.IRequestProvider from any layer it should auto reflected in DataAccess.IRequestProvider layer
Currently I am calling IDomainToRepoMappingRequestProvider.map() each time to set DataAccess.IRequestProvider
public class DomainToRepoMappingRequestProvider : IDomainToRepoMappingRequestProvider { private readonly IMapper _mapper = null; private readonly IRequestProvider _requestProvider = null; private DataAccess.IRequestProvider _dataAccessRequestProvider = null; public DomainToRepoMappingRequestProvider(IRequestProvider requestProvider, DataAccess.IRequestProvider dataAccessRequestProvider, IMapper mapper) { _mapper = mapper; _requestProvider = requestProvider; _dataAccessRequestProvider = dataAccessRequestProvider; } public void Map() { _mapper.Map(_requestProvider, _dataAccessRequestProvider); } } public class RequestProvider : IRequestProvider { private readonly _mappingProvider; private int _someId; public RequestProvider(IDomainToRepoMappingRequestProvider mappingProvider) { _mappingProvider = mappingProvider } public int SomeId { get; set { _someId = value; _mappingProvider.Map(); } } }
I am looking way through Dependency Injection I finding a solution to reflect changes automatically when something is changed without calling map()
You could have a Lambda builder registration call Map() for you I suppose. I don't know that I would recommend trying to deal with this w/ DI.
I'm going to close this for lack of activity.
I have Core in which Interface is declared as
Implementation also define in same layer
and then I have another layer Repo layer in which I am calling another external nuget packages called DataAccess layer
in which I have declared
so In core and DataAccess both layer I have defined IRequestProvider
Lamar code
Scoped use to pass the same instance throughout the request
Automapper is enable
My expectation is when I change something in Core.IRequestProvider from any layer it should auto reflected in DataAccess.IRequestProvider layer
Currently I am calling IDomainToRepoMappingRequestProvider.map() each time to set DataAccess.IRequestProvider
I am looking way through Dependency Injection I finding a solution to reflect changes automatically when something is changed without calling map()