-->

Using Ninject with mocks in F#

2019-08-11 08:31发布

问题:

This question is part of larger question that can be found here

As in out production code we use Ninject and constructor injection our services tend to look like this

public class Service : IService
{
    private readonly IRepository _repository;

    public Service(IRepository repository)
    {
        _repository = repository;
    }

    public Task<IEnumerable<SelectOption>> GetAlLogicOptions()
    {
        return  _repository.GetOptionsAsync();
    }
}

how ever list of constructor parameters may and will change over time. This is the reason that we want to have IoC to also be used in tests.

In C# NUnit this is quite easy as we have Ninject.MockingKernel that always provides mock implementation and in each test fixture we just rebind sut to it real implementation.

How to achieve same thing in F# xUnit.