Skip to content

Package Installation

Mike Hanson edited this page Mar 7, 2019 · 3 revisions

SqlRepo and related components are currently available via NuGet and include the following packages

SqlRepo

This package contains the core components and will usually be installed as a dependency when other packages are installed. However if you are looking to extend SqlRepo or contribute an alternative implementation you can install the package like this:

    Install-Package SqlRepo

or

    dotnet-install-package SqlRepo

SqlRepo.SqlServer

This package contains the core components of a Microsoft SQL Server implementation of SqlRepo it may be installed as a dependency of packages below but you can install the package directly like this:

    Install-Package SqlRepo.SqlServer

or

    dotnet-install-package SqlRepo.SqlServer

SqlRepo.SqlServer.Autofac

This package contains an Autofac module that simplifies the registration of SqlRepo and SqlRepo.SqlServer components for Dependency Injection when using Autofac. You can install the package like this:

    Install-Package SqlRepo.SqlServer.Autofac

or

    dotnet-install-package SqlRepo.SqlServer.Autofac

Once the package is installed you will need to register the module with Autofac using something like this:

    var containerBuilder = new ContainerBuilder();
    containerBuilder.RegisterModule<SqlRepoSqlServerAutofacModule>();

    // other registrations...

    var container = containerBuilder.Build();

SqlRepo.SqlServer.NInject

This package contains a NInject module that simplifies the registration of SqlRepo and SqlRepo.SqlServer components for Dependency Injection when using NInject. You can install the package like this:

    Install-Package SqlRepo.SqlServer.NInject

or

    dotnet-install-package SqlRepo.SqlServer.NInject

Once the package is installed you will need to add the module to the NInject Kernel using something like this:

    IKernel kernel = new StandardKernel(new SqlRepoSqlServerNInjectModule(), ...);

SqlRepo.SqlServer.ServiceCollection

This package contains an extension method that simplifies the registration of SqlRepo and SqlRepo.SqlServer components for Dependency Injection when using the default IoC container with .NET Core. You can install the package like this:

    Install-Package SqlRepo.SqlServer.ServiceCollection

or

    dotnet-install-package SqlRepo.SqlServer.ServiceCollection

Once the package is installed you will need to call the extension method to register SqlRepo and SqlRepo.SqlServer components as services using something like this:

var services = new ServiceCollection()
.AddSqlRepo();

var serviceProvider = services.BuildServiceProvider();

var repositoryFactory = serviceProvider.GetService<IRepositoryFactory>();

This gist provides an example of how you might use the extension method in ASP.NET Core.

SqlRepo.SqlServer.Static

This package contains a static wrapper for our IRepositoryFactory for those who can't or don't want to use Dependency Injection. This might also prove useful if you want to quickly review SqlRepo.SqlServer without having to take the trouble to setup a DI container. You can install the package like this.

    Install-Package SqlRepo.SqlServer.Static

or

    dotnet-install-package SqlRepo.SqlServer.Static

Then you can use it to get a repository like this:

    RepoFactory.Create<ToDo>();

SqlRepo.Testing.NSubstitute

This package contains extension methods that make testing SqlRepo easier when using NSubstitute for mocking. The extension methods allow you to make assertions that components were called as expected without having to write message code using expressions. This code is encapsulated for you.

    Install-Package SqlRepo.Testing.NSubstitute

or

    dotnet-install-package SqlRepo.Testing.NSubstitute

Now in your tests you can make assertions like these:

    selectStatement.ReceivedWhereEquals("Name", expectedName);
    selectStatement.ReceivedAndIn("Status", new []{"Active", "Pending"});