mirror of https://github.com/abpframework/abp.git
14 changed files with 306 additions and 0 deletions
@ -0,0 +1,16 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.8.9" /> |
|||
<ProjectReference Include="..\MyCompanyName.MyModuleName.Domain\MyCompanyName.MyModuleName.Domain.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace MyCompanyName.MyModuleName.EntityFrameworkCore |
|||
{ |
|||
[ConnectionStringName("MyModuleName")] |
|||
public interface IMyModuleNameDbContext : IEfCoreDbContext |
|||
{ |
|||
/* Add DbSet for each Aggregate Root here. Example: |
|||
* DbSet<Question> Questions { get; } |
|||
*/ |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace MyCompanyName.MyModuleName.EntityFrameworkCore |
|||
{ |
|||
[ConnectionStringName("MyModuleName")] |
|||
public class MyModuleNameDbContext : AbpDbContext<MyModuleNameDbContext>, IMyModuleNameDbContext |
|||
{ |
|||
public static string TablePrefix { get; set; } = MyModuleNameConsts.DefaultDbTablePrefix; |
|||
|
|||
public static string Schema { get; set; } = MyModuleNameConsts.DefaultDbSchema; |
|||
|
|||
/* Add DbSet for each Aggregate Root here. Example: |
|||
* public DbSet<Question> Questions { get; set; } |
|||
*/ |
|||
|
|||
public MyModuleNameDbContext(DbContextOptions<MyModuleNameDbContext> options) |
|||
: base(options) |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected override void OnModelCreating(ModelBuilder builder) |
|||
{ |
|||
base.OnModelCreating(builder); |
|||
|
|||
builder.ConfigureMyModuleName(options => |
|||
{ |
|||
options.TablePrefix = TablePrefix; |
|||
options.Schema = Schema; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp; |
|||
|
|||
namespace MyCompanyName.MyModuleName.EntityFrameworkCore |
|||
{ |
|||
public static class MyModuleNameDbContextModelCreatingExtensions |
|||
{ |
|||
public static void ConfigureMyModuleName( |
|||
this ModelBuilder builder, |
|||
Action<MyModuleNameModelBuilderConfigurationOptions> optionsAction = null) |
|||
{ |
|||
Check.NotNull(builder, nameof(builder)); |
|||
|
|||
var options = new MyModuleNameModelBuilderConfigurationOptions(); |
|||
|
|||
optionsAction?.Invoke(options); |
|||
|
|||
/* Configure all entities here. Example: |
|||
|
|||
builder.Entity<Question>(b => |
|||
{ |
|||
//Configure table & schema name
|
|||
//b.ToTable(options.TablePrefix + "Questions", options.Schema);
|
|||
|
|||
//Properties
|
|||
//b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength);
|
|||
|
|||
//Configure relations
|
|||
//b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId);
|
|||
|
|||
//Configure indexes
|
|||
//b.HasIndex(q => q.CreationTime);
|
|||
}); |
|||
*/ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace MyCompanyName.MyModuleName.EntityFrameworkCore |
|||
{ |
|||
[DependsOn( |
|||
typeof(MyModuleNameDomainModule), |
|||
typeof(AbpEntityFrameworkCoreModule) |
|||
)] |
|||
public class MyModuleNameEntityFrameworkCoreModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddAbpDbContext<MyModuleNameDbContext>(options => |
|||
{ |
|||
/* Add custom repositories here. Example: |
|||
* options.AddRepository<Question, EfCoreQuestionRepository>(); |
|||
*/ |
|||
}); |
|||
|
|||
context.Services.AddAssemblyOf<MyModuleNameEntityFrameworkCoreModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.EntityFrameworkCore.Modeling; |
|||
|
|||
namespace MyCompanyName.MyModuleName.EntityFrameworkCore |
|||
{ |
|||
public class MyModuleNameModelBuilderConfigurationOptions : ModelBuilderConfigurationOptions |
|||
{ |
|||
public MyModuleNameModelBuilderConfigurationOptions( |
|||
[NotNull] string tablePrefix = MyModuleNameConsts.DefaultDbTablePrefix, |
|||
[CanBeNull] string schema = MyModuleNameConsts.DefaultDbSchema) |
|||
: base( |
|||
tablePrefix, |
|||
schema) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\MyCompanyName.MyModuleName.Domain\MyCompanyName.MyModuleName.Domain.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace MyCompanyName.MyModuleName.MongoDB |
|||
{ |
|||
public static class AbpUsersMongoDbContextExtensions |
|||
{ |
|||
public static void ConfigureMyModuleName( |
|||
this IMongoModelBuilder builder, |
|||
Action<MongoModelBuilderConfigurationOptions> optionsAction = null) |
|||
{ |
|||
Check.NotNull(builder, nameof(builder)); |
|||
|
|||
var options = new MyModuleNameMongoModelBuilderConfigurationOptions(); |
|||
|
|||
optionsAction?.Invoke(options); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace MyCompanyName.MyModuleName.MongoDB |
|||
{ |
|||
[ConnectionStringName("MyModuleName")] |
|||
public interface IMyModuleNameMongoDbContext : IAbpMongoDbContext |
|||
{ |
|||
/* Define mongo collections here. Example: |
|||
* IMongoCollection<Question> Questions { get; } |
|||
*/ |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace MyCompanyName.MyModuleName.MongoDB |
|||
{ |
|||
public static class MyModuleNameBsonClassMap |
|||
{ |
|||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); |
|||
|
|||
public static void Configure() |
|||
{ |
|||
OneTimeRunner.Run(() => |
|||
{ |
|||
//Register mappings here. Example:
|
|||
//BsonClassMap.RegisterClassMap<Question>(map =>
|
|||
//{
|
|||
// map.AutoMap();
|
|||
//});
|
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace MyCompanyName.MyModuleName.MongoDB |
|||
{ |
|||
[ConnectionStringName("MyModuleName")] |
|||
public class MyModuleNameMongoDbContext : AbpMongoDbContext, IMyModuleNameMongoDbContext |
|||
{ |
|||
public static string CollectionPrefix { get; set; } = MyModuleNameConsts.DefaultDbTablePrefix; |
|||
|
|||
/* Add mongo collections here. Example: |
|||
* public IMongoCollection<Question> Questions => Collection<Question>(); |
|||
*/ |
|||
|
|||
protected override void CreateModel(IMongoModelBuilder modelBuilder) |
|||
{ |
|||
base.CreateModel(modelBuilder); |
|||
|
|||
modelBuilder.ConfigureMyModuleName(options => |
|||
{ |
|||
options.CollectionPrefix = CollectionPrefix; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace MyCompanyName.MyModuleName.MongoDB |
|||
{ |
|||
[DependsOn( |
|||
typeof(MyModuleNameDomainModule), |
|||
typeof(AbpMongoDbModule) |
|||
)] |
|||
public class MyModuleNameMongoDbModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
MyModuleNameBsonClassMap.Configure(); |
|||
|
|||
context.Services.AddMongoDbContext<MyModuleNameMongoDbContext>(options => |
|||
{ |
|||
/* Add custom repositories here. Example: |
|||
* options.AddRepository<Question, MongoQuestionRepository>(); |
|||
*/ |
|||
}); |
|||
|
|||
context.Services.AddAssemblyOf<MyModuleNameMongoDbModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace MyCompanyName.MyModuleName.MongoDB |
|||
{ |
|||
public class MyModuleNameMongoModelBuilderConfigurationOptions : MongoModelBuilderConfigurationOptions |
|||
{ |
|||
public MyModuleNameMongoModelBuilderConfigurationOptions( |
|||
[NotNull] string tablePrefix = MyModuleNameConsts.DefaultDbTablePrefix) |
|||
: base(tablePrefix) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue