Skip to content

Instantly share code, notes, and snippets.

@PradeepLoganathan
Last active July 30, 2020 10:04
Show Gist options
  • Select an option

  • Save PradeepLoganathan/e87a8b14ec396f19120cd4c7e83acd4f to your computer and use it in GitHub Desktop.

Select an option

Save PradeepLoganathan/e87a8b14ec396f19120cd4c7e83acd4f to your computer and use it in GitHub Desktop.
inject repositories and DbContext
using BookStore.Domain.BooksAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace BookStore.Repository
{
public static class DependencyInjection
{
public static IServiceCollection AddRepository(this IServiceCollection services)
{
services.AddTransient<IBooksRepository, BooksRepository>();
services.AddTransient<ICatalogueRepository, CatalogueRepository>();
services.AddTransient<IUnitOfWork, UnitOfWork>();
services.AddDbContext<BookStoreDbContext>(opt => opt
.UseSqlServer("Server=localhost,1433; Database=BooksDB;User Id=sa; Password=password_01;"));
return services;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment