title: Configuration services without reference Infrastructure in mvc core
body: <p>When using Clean Architecture in Mvc Core, Layer with Name can be like this:</p>
  
  <ol>
  <li>Infrastructure</li>
  <li>Core</li>
  <li>Web</li>
  </ol>
  
  <p>This link has complete description about that:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/dotnet/standard/modern-web-apps-azure-architecture/common-web-application-architectures" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/standard/modern-web-apps-azure-architecture/common-web-application-architectures</a></p>
  
  <p>Principles says that Web project shouldn't have any reference from Infrastructure class library. So how can use a DI container to resolve the problem?</p>
  
  <p>This code in <code>Startup.cs</code> uses Infrastructure to config some things:</p>
  
  <pre><code>public void ConfigureProductionServices(IServiceCollection services)
  {
      services.AddDbContext&lt;CatalogContext&gt;(c =&gt;
      {
          try
          {
              c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection"));
          }
          catch (Exception ex)
          {
              var message = ex.Message;
          }
      });
  
      services.AddDbContext&lt;AppIdentityDbContext&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString("CatalogConnection")));
  
      ConfigureServices(services);
  }
  
  public void ConfigureServices(IServiceCollection services)
  {
      services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;()
          .AddEntityFrameworkStores&lt;AppIdentityDbContext&gt;()
          .AddDefaultTokenProviders();
  
      services.AddScoped(typeof(IRepository&lt;&gt;), typeof(EfRepository&lt;&gt;));
      .
      .
      _services = services;
  }
  </code></pre>