You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a base class for all our Tests.
However, to minimize the overall runtime, we only instanciate those dependecies when they are actually needed.
This helped to greatly reduce the time it takes to execute all tests.
Now, I would like to use Automocker instead of ServiceCollection/ServiceProvider.
The only thing that is missing is a way to defer instanciation of dependencies.
My suggestion would be something along the lines of:
// current way
mocker.Use<IDriveTrain>(new DriveTrain());// new overload
mocker.Use<IDriveTrain>(_ =>new DriveTrain());
which would defer the Instanciation until eg var car = mocker.CreateInstance<Car>(); is called.
I think this is a pretty minor change and i'd gladly provide a PR for this, if you folks think that is not a terrible idea.
The text was updated successfully, but these errors were encountered:
This is technically possible today, albeit with a more complex API. The AutoMocker instance has a Resolvers property where you can pass in your own IMockResolver instance. Under the hood, most of the resolutions fall into these resolvers.
I suspect it would not be too difficult to have some sort of "DeferredInstanceResolver" that could contain those delegates and invokes them to get the instances.
If you would like to submit a PR for it, I would be happy to review it.
We have a base class for all our Tests.
However, to minimize the overall runtime, we only instanciate those dependecies when they are actually needed.
This helped to greatly reduce the time it takes to execute all tests.
Now, I would like to use Automocker instead of ServiceCollection/ServiceProvider.
The only thing that is missing is a way to defer instanciation of dependencies.
My suggestion would be something along the lines of:
which would defer the Instanciation until eg
var car = mocker.CreateInstance<Car>();
is called.I think this is a pretty minor change and i'd gladly provide a PR for this, if you folks think that is not a terrible idea.
The text was updated successfully, but these errors were encountered: