Nikita
Nikita

Reputation: 64

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

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:

Upvotes: 1

Views: 1467

Answers (0)

Related Questions