Skip to content

Commit

Permalink
修改md
Browse files Browse the repository at this point in the history
  • Loading branch information
longxianghui committed Sep 29, 2019
1 parent 09d6431 commit 1c99aa6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class SchoolRepository: EfCoreRepository<School>,ISchoolRepository
```
创建上下文,继承BaseDbContext,如果你不需要操作上下文可以不用做这一步
```
public class KingDbContext : BaseDbContext
public class ChimpDbContext : BaseDbContext
{
public KingDbContext(DbContextOptions options) : base(options)
public ChimpDbContext(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand All @@ -57,16 +57,16 @@ public class KingDbContext : BaseDbContext
```
注入服务
```
services.AddKing<KingDbContext>(
services.AddChimp<ChimpDbContext>(
opt =>
opt.UseSqlServer("Server=10.0.0.99;Database=king;Uid=sa;Pwd=Fuluerp123")
opt.UseSqlServer("Server=10.0.0.99;Database=chimp;Uid=sa;Pwd=Fuluerp123")
);
```
如果你没有创建上下文
```
services.AddKing(
services.AddChimp(
opt =>
opt.UseSqlServer("Server=10.0.0.99;Database=king;Uid=sa;Pwd=Fuluerp123")
opt.UseSqlServer("Server=10.0.0.99;Database=chimp;Uid=sa;Pwd=Fuluerp123")
);
```
在Controller中使用
Expand Down
4 changes: 2 additions & 2 deletions src/Leo.Chimp/ServiceCollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtension
{
public static IServiceCollection AddKing(this IServiceCollection services,
public static IServiceCollection AddChimp(this IServiceCollection services,
Action<DbContextOptionsBuilder> options)
{
services.AddDbContext<BaseDbContext>(options);
services.AddScoped<DbContext, BaseDbContext>();
AddDefault(services);
return services;
}
public static IServiceCollection AddKing<T>(this IServiceCollection services,
public static IServiceCollection AddChimp<T>(this IServiceCollection services,
Action<DbContextOptionsBuilder> options) where T : BaseDbContext
{
services.AddDbContext<T>(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace Leo.Chimp.Test
{
public class KingDbContext : BaseDbContext
public class ChimpDbContext : BaseDbContext
{
public KingDbContext(DbContextOptions options) : base(options)
public ChimpDbContext(DbContextOptions options) : base(options)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
namespace Leo.Chimp.Test
{

public class KingDbContextTest
public class ChimpDbContextTest
{
private readonly IUnitOfWork _unitOfWork;
private readonly ISchoolRepository _schoolRepository;
public KingDbContextTest()
public ChimpDbContextTest()
{
var services = new ServiceCollection();
services.AddKing<KingDbContext>(opt =>
services.AddChimp<ChimpDbContext>(opt =>
{
opt.UseMySql("server = 10.0.0.146;database=king;uid=root;password=123456;");
});
Expand Down
4 changes: 2 additions & 2 deletions test/Leo.Chimp.Test/DapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class DapperTest
public DapperTest()
{
var services = new ServiceCollection();
services.AddKing(opt => { opt.UseMySql("server = 10.0.0.146;database=king;uid=root;password=123456;"); });
//services.AddKing(opt => { opt.UseSqlServer("Server=10.0.0.99;Database=king;Uid=sa;Pwd=Fuluerp123"); });
services.AddChimp(opt => { opt.UseMySql("server = 10.0.0.146;database=king;uid=root;password=123456;"); });
//services.AddChimp(opt => { opt.UseSqlServer("Server=10.0.0.99;Database=king;Uid=sa;Pwd=Fuluerp123"); });
var sp = services.BuildServiceProvider();
_unitOfWork = sp.GetRequiredService<IUnitOfWork>();
_schoolRepository = sp.GetRequiredService<ISchoolRepository>();
Expand Down
4 changes: 2 additions & 2 deletions test/Leo.Chimp.Test/EfRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public EfRepositoryTest()
{
var services = new ServiceCollection();

services.AddKing(opt =>
services.AddChimp(opt =>
{
opt.UseMySql("server = 10.0.0.146;database=king;uid=root;password=123456;");
});

//services.AddKing(opt =>
//services.AddChimp(opt =>
//{
// opt.UseSqlServer("Server=10.0.0.99;Database=king;Uid=sa;Pwd=Fuluerp123");
//});
Expand Down

0 comments on commit 1c99aa6

Please sign in to comment.