public async Task <IEnumerable <Joke> > GetAllJokesAsync() { using (var uow = _unitOfWorkProvider.CreateUnitOfWork()) { var repository = uow.GetRepository <Joke>(); return(await repository.GetAllAsync(null)); } }
public DataPage <TEntity> Get(int pageNumber, int pageLength, OrderBy <TEntity> orderby = null, Func <IQueryable <TEntity>, IQueryable <TEntity> > includes = null) { using (var uow = _uowProvider.CreateUnitOfWork(false)) { var repository = uow.GetRepository <TEntity>(); var startRow = (pageNumber - 1) * pageLength; var data = repository.GetPage(startRow, pageLength, includes: includes, orderBy: orderby?.Expression); var totalCount = repository.Count(); return(CreateDataPage(pageNumber, pageLength, data, totalCount)); } }
public void AddCassandra() { IServiceProvider serviceProvider = InitDependencyInjection(services => { services.AddLogging(); }, containerBuilder => { containerBuilder.AddUnitOfWork(provider => { provider.Register(new CassandraUnitOfWorkRegisteration(new CassandraOptions { Nodes = new string[] { "192.168.40.229" }, User = "******", Password = "******", KeySpace = "ias" })); }); }); IUnitOfWorkProvider unitOfWorkProvider = serviceProvider.GetService <IUnitOfWorkProvider>(); using (IUnitOfWork uw = unitOfWorkProvider.CreateUnitOfWork("cassandra")) { Assert.IsNotNull(uw); var repository = uw.CreateRepository <RTLSAreaDataDayRepository>(); Assert.IsNotNull(repository); } }
public void AddEntityFramework() { IServiceProvider serviceProvider = InitDependencyInjection(services => { services.AddDbContext <Context.TestContext>(builder => { builder.UseInMemoryDatabase(); }, ServiceLifetime.Transient); }, containerBuilder => { containerBuilder.AddUnitOfWork(provider => { provider.Register(new EntityFrameworkUnitOfWorkRegisteration("ef")); }); }); IUnitOfWorkProvider unitOfWorkProvider = serviceProvider.GetService <IUnitOfWorkProvider>(); using (IUnitOfWork uw = unitOfWorkProvider.CreateUnitOfWork("ef")) { Assert.IsNotNull(uw); var entity = new Context.TestContext.TestEntity { ID = 1, Name = "name" }; uw.Insert(entity); entity = uw.Get <Context.TestContext.TestEntity>(t => t.ID == 1); Assert.IsNotNull(entity); } }
public void AddCassandra() { IServiceProvider serviceProvider = InitDependencyInjection(services => { }, containerBuilder => { containerBuilder.AddUnitOfWork(provider => { provider.AddCassandra("cassandra", new UnitOfWork.Cassandra.CassandraOptions { Nodes = new string[] { "192.168.40.229" }, User = "******", Password = "******", KeySpace = "ias_dev" }, builder => { }); }); }); IUnitOfWorkProvider unitOfWirkProvider = serviceProvider.GetService <IUnitOfWorkProvider>(); using (IUnitOfWork uw = unitOfWirkProvider.CreateUnitOfWork("cassandra")) { Assert.IsNotNull(uw); var entityList = uw.Query <Entity.RTLSAreaDataDay>(t => t.Day == 20161129); Assert.IsTrue(entityList.Count > 0); } }
public void CannotRetriveRepositoryAcrossUnitOfWork() { IServiceProvider serviceProvider = InitDependencyInjection(services => { services.AddDbContext <Context.TestContext>(builder => { builder.UseInMemoryDatabase(); }, ServiceLifetime.Transient); }, containerBuilder => { containerBuilder.AddUnitOfWork(provider => { provider.AddEntityFramework <Context.TestContext>("ef1", builder => { builder.RegisterType <Repository.EntityFramework.TestEntityRepository>().As <Repository.Interface.ITestEntityRepository>(); }); provider.AddEntityFramework <Context.TestContext>("ef2"); }); }); IUnitOfWorkProvider unitOfWirkProvider = serviceProvider.GetService <IUnitOfWorkProvider>(); using (IUnitOfWork uw = unitOfWirkProvider.CreateUnitOfWork("ef1")) { Repository.Interface.ITestEntityRepository repository = uw.CreateRepository <Repository.Interface.ITestEntityRepository>(); Assert.IsNotNull(repository); var entityList = repository.All(); } using (IUnitOfWork uw = unitOfWirkProvider.CreateUnitOfWork("ef2")) { try { Repository.Interface.ITestEntityRepository repository = uw.CreateRepository <Repository.Interface.ITestEntityRepository>(); Assert.IsNull(repository); } catch { } } }
public void RepositoryMethodOverrideShouldWork() { IServiceProvider serviceProvider = InitDependencyInjection(services => { services.AddLogging(); services.AddDbContext <Context.TestContext>(builder => { builder.UseInMemoryDatabase(); }, ServiceLifetime.Transient); }, containerBuilder => { containerBuilder.AddUnitOfWork(provider => { provider.Register(new EntityFrameworkUnitOfWorkRegisteration("ef", builder => { //builder.RegisterType<Repository.EntityFramework.TestEntityRepository>().As<Repository.Interface.ITestEntityRepository>(); })); }); }); IUnitOfWorkProvider unitOfWorkProvider = serviceProvider.GetService <IUnitOfWorkProvider>(); using (var uw = unitOfWorkProvider.CreateUnitOfWork("ef")) { var entity = new Context.TestContext.TestEntity { ID = 1, Name = "hello" }; uw.Insert(entity); entity = uw.Get <Context.TestContext.TestEntity>(t => t.ID == 1); Assert.AreEqual(entity.Name, "override"); } }