I'm sure that this questions has been asked several times, but I'm stuck in a rut on this one. I am attempting to automap properties from EF objects to defined interfaces. I'm using simple injector as my choice of IOC framework. (win forms)
I've registered my interfaces within the program.cs ..
container = new Container();
container.Register<IBob, Bob>();
...
and pass an instance of the container into the class where I'm doing the automapping ...
public ModelService(IDataRepository repo, Container container)
{
// create a reference to the repository
this.Repository = repo;
var config = new MapperConfiguration(cfg =>
{
// pass the reference into the constructor service.
qcfg.ConstructServicesUsing(type => container.GetInstance(type));
cfg.AddProfile<ModelConfig>();
});
mapper = new Mapper(config);
}
The profile class looks a little bit like this ...
public class ModelConfig : Profile
{
public ModelsConfig()
{
// mapping definition for product buy
this.CreateMap<Entity.BobEF, IBob>()
.ForMember(destination => destination.UniqueIdentifier, option => option.MapFrom(source => source.BobID))
.ReverseMap();
}
So I was expecting automapper to use the container to create a concrete class for IBob given that this has already been declared within the BI bootstrapping and it should be using the "container.GetInstance()" method to resolve the interface, however what I'm actually getting in a proxy representation of the IBob class with a type of Proxy_MyProject.IBob_232342
I really don't understand the automapper documentation for this as I'm new to using automapper.
Any HELP very much appreciated.
Regards,
Tim
Edit: (Example of model classes being used)
// shows the basic interface for a product
public interface IProduct : IModel
{
string Name { get; set; }
ISupplier Supplier { get; set; }
}
// shows the concrete implementation including the
// exposed property being of type ISupplier
public class Product : Model, IProduct
{
public string Name
{
get;
set;
}
public ISupplier Supplier
{
get;
set;
}
}