Skip to content

Instantly share code, notes, and snippets.

@ivanpaulovich
Created July 22, 2018 10:14
Show Gist options
  • Save ivanpaulovich/b2e66b47612faf1a95ea23b70e772394 to your computer and use it in GitHub Desktop.
Save ivanpaulovich/b2e66b47612faf1a95ea23b70e772394 to your computer and use it in GitHub Desktop.
Module.cs
public class Module : Autofac.Module
{
public string ConnectionString { get; set; }
protected override void Load(ContainerBuilder builder)
{
var optionsBuilder = new DbContextOptionsBuilder<DbContext>();
optionsBuilder.UseSqlServer(ConnectionString);
optionsBuilder.EnableSensitiveDataLogging(true);
builder.RegisterType<Context>()
.WithParameter(new TypedParameter(typeof(DbContextOptions), optionsBuilder.Options))
.InstancePerLifetimeScope();
//
// Register all Types in EntityFrameworkDataAccess namespace
//
builder.RegisterAssemblyTypes(typeof(InfrastructureException).Assembly)
.Where(type => type.Namespace.Contains("EntityFrameworkDataAccess"))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment