public static IServiceCollection AddNHibernate(this IServiceCollection services, string connectionString) { var sessionFactory = SessionFactory.BuildSessionFactory(connectionString); services.AddSingleton(sessionFactory); services.AddScoped(factory => sessionFactory.OpenSession()); services.AddScoped(typeof(IMapperSession <>), typeof(MapperSession <>)); return(services); }
public IEnumerable <Employee> GetAll() { var sessionFactory = SessionFactory.BuildSessionFactory(); using (var session = sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { return(session.CreateCriteria(typeof(Employee)).List <Employee>().AsEnumerable()); } } }