Skip to content
Mike Hanson edited this page Feb 25, 2018 · 2 revisions

Inversion of Control (IoC) is a principle which basically suggests that instead of components creating instances of framework or library types they declare a dependency on the type and require the application to provide an instance.

Dependency Injection (DI) is a very common implementation of IoC where as the name suggests dependencies are injected into a component that needs them. This often achieved through Constructor Injection although Property Injection is also used.

SqlRepo is designed to work well with DI and along with the core components we provide libraries to simplify the registration of types in many common IoC containers.

Currently we provide support for the following containers via NuGet Packages

  • Autofac
  • Ninject
  • ServiceCollection (.NET Core)

By using one of our supplied packages you can quickly get set up with SqlRepo such that all you need to do is declare a dependency on IRepositoryFactory and you are good to go e.g.

Install-Package SqlRepo.SqlServer.Autofac
``

```csharp

// Program.cs
using Autofac;
using SqlRepo.SqlServer.Autofac;

static class Program
{
    static IContainer Container {get, private set;}

    public void Main(params string[] args)
    {
        var containerBuilder = new ContainerBuilder();
        containerBuilder.RegisterModule<SqlRepoSqlServerAutofacModule>();
        Container = containerBuilder.Build();
    }
}

// GettingStarted.cs
using SqlRepo;

public class GettingStarted
{
    private IRepositoryFactory repositoryFactory;

    public GettingStarted(IRepositoryFactory repositoryFactory)
    {
        this.repositoryFactory = repositoryFactory;
    }
}

For more information on installing are registering SqlRepo components see Installation