mirror of https://github.com/abpframework/abp
Resolved #93: MemoryDb implementation.
parent
073f97ee0f
commit
42438d5308
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.MemoryDb</AssemblyName>
|
||||
<PackageId>Volo.Abp.MemoryDb</PackageId>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Volo.Abp\Volo.Abp.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.MemoryDb;
|
||||
|
||||
namespace Volo.Abp.Domain.Repositories.MemoryDb
|
||||
{
|
||||
public class MemoryDbRepository<TMemoryDbContext, TEntity> : MemoryDbRepository<TMemoryDbContext, TEntity, Guid>, IMemoryDbRepository<TEntity>
|
||||
where TMemoryDbContext : MemoryDbContext
|
||||
where TEntity : class, IEntity<Guid>
|
||||
{
|
||||
public MemoryDbRepository(IMemoryDatabaseProvider<TMemoryDbContext> databaseProvider)
|
||||
: base(databaseProvider)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class MemoryDbRepository<TMemoryDbContext, TEntity, TPrimaryKey> : QueryableRepositoryBase<TEntity, TPrimaryKey>, IMemoryDbRepository<TEntity, TPrimaryKey>
|
||||
where TMemoryDbContext : MemoryDbContext
|
||||
where TEntity : class, IEntity<TPrimaryKey>
|
||||
{
|
||||
public virtual List<TEntity> Collection => Database.Collection<TEntity>();
|
||||
|
||||
public virtual IMemoryDatabase Database => DatabaseProvider.GetDatabase();
|
||||
|
||||
protected IMemoryDatabaseProvider<TMemoryDbContext> DatabaseProvider { get; }
|
||||
|
||||
public MemoryDbRepository(IMemoryDatabaseProvider<TMemoryDbContext> databaseProvider)
|
||||
{
|
||||
DatabaseProvider = databaseProvider;
|
||||
}
|
||||
|
||||
public override TEntity Insert(TEntity entity, bool autoSave = false)
|
||||
{
|
||||
Collection.Add(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public override TEntity Update(TEntity entity)
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
|
||||
public override void Delete(TEntity entity)
|
||||
{
|
||||
Collection.Remove(entity);
|
||||
}
|
||||
|
||||
protected override IQueryable<TEntity> GetQueryable()
|
||||
{
|
||||
return Collection.AsQueryable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
using Volo.Abp.Data;
|
||||
|
||||
namespace Volo.Abp.MemoryDb.DependencyInjection
|
||||
{
|
||||
public interface IMemoryDbContextRegistrationOptionsBuilder : ICommonDbContextRegistrationOptionsBuilder
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
using Volo.Abp.Data;
|
||||
|
||||
namespace Volo.Abp.MemoryDb.DependencyInjection
|
||||
{
|
||||
public class MemoryDbContextRegistrationOptions : CommonDbContextRegistrationOptions, IMemoryDbContextRegistrationOptionsBuilder
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Domain.Repositories.MemoryDb;
|
||||
|
||||
namespace Volo.Abp.MemoryDb.DependencyInjection
|
||||
{
|
||||
public class MemoryDbRepositoryRegistrar : RepositoryRegistrarBase<MemoryDbContextRegistrationOptions>
|
||||
{
|
||||
public MemoryDbRepositoryRegistrar(MemoryDbContextRegistrationOptions options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override IEnumerable<Type> GetEntityTypes(Type dbContextType)
|
||||
{
|
||||
var memoryDbContext = (MemoryDbContext)Activator.CreateInstance(dbContextType);
|
||||
return memoryDbContext.GetEntityTypes();
|
||||
}
|
||||
|
||||
protected override Type GetRepositoryTypeForDefaultPk(Type dbContextType, Type entityType)
|
||||
{
|
||||
return typeof(MemoryDbRepository<,>).MakeGenericType(dbContextType, entityType);
|
||||
}
|
||||
|
||||
protected override Type GetRepositoryType(Type dbContextType, Type entityType, Type primaryKeyType)
|
||||
{
|
||||
return typeof(MemoryDbRepository<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Volo.Abp.MemoryDb
|
||||
{
|
||||
public abstract class MemoryDbContext
|
||||
{
|
||||
private static readonly Type[] EmptyTypeList = new Type[0];
|
||||
|
||||
public virtual IReadOnlyList<Type> GetEntityTypes()
|
||||
{
|
||||
return EmptyTypeList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.MemoryDb.Tests</AssemblyName>
|
||||
<PackageId>Volo.Abp.MemoryDb.Tests</PackageId>
|
||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
|
||||
<ProjectReference Include="..\..\src\Volo.Abp.MemoryDb\Volo.Abp.MemoryDb.csproj" />
|
||||
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
|
||||
<ProjectReference Include="..\Volo.Abp.TestApp\Volo.Abp.TestApp.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in new issue