Created
November 22, 2020 08:06
-
-
Save sunilkumarmedium/570ea844459ba191e95cc641b4278edd to your computer and use it in GitHub Desktop.
NHibernateServiceRegistration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CleanArchitectureApp.Infrastructure.Persistence | |
{ | |
public static class ServiceRegistration | |
{ | |
public static void AddPersistenceInfrastructure(this IServiceCollection services, IConfiguration configuration) | |
{ | |
var mapper = new ModelMapper(); | |
mapper.AddMappings(typeof(UserMap).Assembly.ExportedTypes); | |
HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); | |
var NHConfiguration = new Configuration(); | |
NHConfiguration.DataBaseIntegration(c => | |
{ | |
c.Dialect<MsSql2008Dialect>(); | |
c.ConnectionString = configuration.GetConnectionString("DefaultConnection"); | |
c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote; | |
c.LogFormattedSql = true; | |
c.LogSqlInConsole = true; | |
}); | |
NHConfiguration.AddMapping(domainMapping); | |
var sessionFactory = NHConfiguration.BuildSessionFactory(); | |
services.AddSingleton(sessionFactory); | |
services.AddScoped(factory => sessionFactory.OpenSession()); | |
#region Repositories | |
services.AddTransient(typeof(IGenericRepositoryAsync<>), typeof(GenericRepositoryAsync<>)); | |
services.AddTransient<IUserRepositoryAsync, UserRepositoryAsync>(); | |
services.AddTransient<IUserStatusRepositoryAsync, UserStatusRepositoryAsync>(); | |
services.AddTransient<ILoginLogRepositoryAsync, LoginLogRepositoryAsync>(); | |
services.AddTransient<ILoginLogTypeRepositoryAsync, LoginLogTypeRepositoryAsync>(); | |
services.AddTransient<IUserTokenRepositoryAsync, UserTokenRepositoryAsync>(); | |
services.AddTransient<IEmailTemplateRepositoryAsync, EmailTemplateRepositoryAsync>(); | |
services.AddTransient<IEmailRecipientRepositoryAsync, EmailRecipientRepositoryAsync>(); | |
#endregion Repositories | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment