I have a MyProject project where I have IMyService
interface and MyService
class that implements IMyService
. In Startup.cs class I dependency injection them:
// MyProject project | Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IMyService, MyService>();
}
Because MyService
has many dependencies (makes many REST calls to 3rd party etc.) I would like to create a stub version of it for development environment. I created new MyStubsProject that references to MyProject. And I implemented stub version of IMyService
to MyStubsProject:
// MyStubsProject project
public class MyStubService : IMyService
{
...
}
So now I want to add dependency injection to Startup.cs class:
// MyProject project | Startup.cs
public void ConfigureServices(IServiceCollection services)
{
if (isDevelopmentEnvironment)
services.AddScoped<IMyService, MyStubService>();
else
services.AddScoped<IMyService, MyService>();
}
But if I add that, there will be circular dependency between MyProject and MyStubsProject.
How should I implement reference to the class MyStubService
or MyStubsProject project in Startup.cs?