Automapper and StructureMap proper instance registration .net Core
Asked Answered
G

0

8

At the moment this is the way I wire up IMapper instance of Automapper with StructureMap.

public class DefaultRegistry : Registry
{
    public DefaultRegistry()
    {
        Scan(o =>
        {
            o.AddAllTypesOf<Profile>();
        });
  
        For<IMapper>().Use(() => Mapper.Instance);
    }
}

In net core startup:

var container = new Container(new DefaultRegistry());
container.Populate(services);

services.AddAutoMapper(cfg => cfg.ConstructServicesUsing(container.GetInstance));
Mapper.AssertConfigurationIsValid();

Since Mapper.Instance creates static, how can I register it as an instance? Or what is the proper way to wire it up with StructureMap?

Goodhen answered 26/1, 2017 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.