0

Whenever there is a new dependency identified, we need to declare it into ConfigureServices method of Startup class. By the time I have added more than 30 such services and it keep on increasing by time. This is where we see volition of Open/Closed Principle.

Please suggest a solution this violation.

public void ConfigureServices(IServiceCollection services)
{                
    services.AddRepository<SqlContext>(Configuration);
    services.AddHttpContextAccessor();
    services.RegisterHttpClients(Configuration);
    services.AddSwaggerGen(Configuration);
    services.AddCors(Configuration);
    services.AddAuthorization(Configuration);
    services.AddApplicationInsightsTelemetry(Configuration);
    services.AddMvc(Configuration);
    services.AddApiVersioning(Configuration);
    services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>();
    .
    .
    .
    .
    .
    .
}
Steven
  • 166,672
  • 24
  • 332
  • 435
Vipul
  • 1,563
  • 4
  • 22
  • 46
  • 2
    Your question is not clear! What are you expecting in this case? Are your trying to move the service registrations from `ConfigureServices` method to anywhere? – TanvirArjel Jan 04 '19 at 10:11
  • 1
    Your question is broad and there are many possible answers to your question. You could try using Auto-Registration mixed with Convention over Configuration, possibly in combination with changes to your application design. But again, it all depends. There's a good book that actually discusses many of these topics, by Mark Seemann (and myself), which is called [Dependency Injection: Principles, Practices, Patterns](https://manning.com/seemann2). – Steven Jan 04 '19 at 16:21

0 Answers0