.NET Core, DI LightInject: How to inject a dependency in a Static class?

1.4k Views Asked by At

Please help me sort it out.. ;)

How to inject a dependency in a static class?

I want to inject Mapper into a static class. I read the documentation and google about LightInject and did not find how to implement it .. Or is there a better solution for my task, not only through DI?

public static class MapExtension
{
    public static IMapper Mapper { get; set; }

    public static TModel Map<TModel, TData>(TData data)
        where TModel : IModel
        where TData : IData
    {

        TModel model = Mapper.Map<TModel>(data);

        return model;
    }
}

I use:

  • ASP.NET CORE MVC 3
  • LightInject 6.3.4 (latest version)
  • AutoMapper 10.0.0
0

There are 0 best solutions below