diff --git a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs index 91899a0ca1..79f3a1e626 100644 --- a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs +++ b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs @@ -7,7 +7,7 @@ namespace Volo.Abp.AspNetCore.MultiTenancy { public const string TenantIdKey = "__tenantId"; - public void Resolve(ICurrentTenantResolveContext context) + public void Resolve(ITenantResolveContext context) { var httpContext = context.GetHttpContext(); if (httpContext == null) diff --git a/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpDbContextConfigurationContext.cs b/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpDbContextConfigurationContext.cs index 2d105ddf82..3144a440c8 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpDbContextConfigurationContext.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpDbContextConfigurationContext.cs @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.DependencyInjection public string ModuleName { get; } //TODO: Use a SchemaName/DatabaseName instead? - public virtual DbContextOptionsBuilder DbContextOptions { get; protected set; } + public DbContextOptionsBuilder DbContextOptions { get; protected set; } public AbpDbContextConfigurationContext(string connectionString, [CanBeNull] string moduleName) { diff --git a/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs b/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs index d74d5a77db..86d87634fd 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; -using Volo.Abp.Repositories.EntityFrameworkCore; namespace Microsoft.Extensions.DependencyInjection { @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.DependencyInjection this IServiceCollection services) where TDbContext : AbpDbContext { - services //TODO: This are copied from EntityFrameworkServiceCollectionExtensions, we should think on that later + services //TODO: This code is copied from EntityFrameworkServiceCollectionExtensions, we should think on that later .AddMemoryCache() .AddLogging(); diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs similarity index 91% rename from src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs rename to src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs index 646259f941..100a66363d 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs @@ -1,10 +1,9 @@ using System; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Entities; -using Volo.Abp.Domain.Repositories; -using Volo.Abp.Repositories.EntityFrameworkCore; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; -namespace Volo.Abp.Repositories +namespace Volo.Abp.Domain.Repositories { public static class EfCoreRepositoryExtensions { diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs similarity index 96% rename from src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs rename to src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index f7754fd058..0ddd648fe5 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -3,10 +3,9 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Entities; -using Volo.Abp.Domain.Repositories; using Volo.Abp.EntityFrameworkCore; -namespace Volo.Abp.Repositories.EntityFrameworkCore +namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { public class EfCoreRepository : QueryableRepositoryBase, IEfCoreRepository where TDbContext : AbpDbContext diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs similarity index 78% rename from src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs rename to src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs index 3f2d08f9f6..f7099e57f7 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs @@ -1,8 +1,7 @@ using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Entities; -using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.Repositories.EntityFrameworkCore +namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { public interface IEfCoreRepository : IQueryableRepository where TEntity : class, IEntity diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs index 1411daa38e..6c1947ebd7 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Modularity; -using Volo.Abp.Repositories.EntityFrameworkCore; +using Volo.Abp.Uow.EntityFrameworkCore; namespace Volo.Abp.EntityFrameworkCore { @@ -9,8 +9,8 @@ namespace Volo.Abp.EntityFrameworkCore { public override void ConfigureServices(IServiceCollection services) { - //TODO: This will be changed! services.TryAddTransient(typeof(IDbContextProvider<>), typeof(UnitOfWorkDbContextProvider<>)); + services.AddAssemblyOf(); } } } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IDbContextProvider.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/IDbContextProvider.cs similarity index 63% rename from src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IDbContextProvider.cs rename to src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/IDbContextProvider.cs index f28ad52501..d975596df1 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IDbContextProvider.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/IDbContextProvider.cs @@ -1,6 +1,4 @@ -using Volo.Abp.EntityFrameworkCore; - -namespace Volo.Abp.Repositories.EntityFrameworkCore +namespace Volo.Abp.EntityFrameworkCore { public interface IDbContextProvider where TDbContext : AbpDbContext diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/DbContextDatabaseApi.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/DbContextDatabaseApi.cs new file mode 100644 index 0000000000..cf08eab64f --- /dev/null +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/DbContextDatabaseApi.cs @@ -0,0 +1,26 @@ +using System.Threading.Tasks; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.Uow.EntityFrameworkCore +{ + public class DbContextDatabaseApi : IDatabaseApi + where TDbContext : AbpDbContext + { + public TDbContext DbContext { get; } + + public DbContextDatabaseApi(TDbContext dbContext) + { + DbContext = dbContext; + } + + public Task SaveChangesAsync() + { + return DbContext.SaveChangesAsync(); + } + + public Task CommitAsync() + { + return DbContext.SaveChangesAsync(); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs similarity index 70% rename from src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs rename to src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs index 4601cec847..f62aec9a18 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs @@ -1,11 +1,8 @@ -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; -using Volo.Abp.Uow; -namespace Volo.Abp.Repositories.EntityFrameworkCore +namespace Volo.Abp.Uow.EntityFrameworkCore { public class UnitOfWorkDbContextProvider : IDbContextProvider where TDbContext : AbpDbContext @@ -41,25 +38,4 @@ namespace Volo.Abp.Repositories.EntityFrameworkCore return ((DbContextDatabaseApi)databaseApi).DbContext; } } - - public class DbContextDatabaseApi : IDatabaseApi - where TDbContext : AbpDbContext - { - public TDbContext DbContext { get; } - - public DbContextDatabaseApi(TDbContext dbContext) - { - DbContext = dbContext; - } - - public Task SaveChangesAsync() - { - return DbContext.SaveChangesAsync(); - } - - public Task CommitAsync() - { - return DbContext.SaveChangesAsync(); - } - } } \ No newline at end of file diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/AsyncLocalTenantScopeProvider.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/AsyncLocalTenantScopeProvider.cs index dcc0a6f507..06dfb84c09 100644 --- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/AsyncLocalTenantScopeProvider.cs +++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/AsyncLocalTenantScopeProvider.cs @@ -4,7 +4,7 @@ using Volo.DependencyInjection; namespace Volo.Abp.MultiTenancy { - public class AsyncLocalTenantScopeProvider : ITenantScopeProvider, IScopedDependency + public class AsyncLocalTenantScopeProvider : ITenantScopeProvider, ISingletonDependency { public TenantScope CurrentScope { @@ -19,10 +19,10 @@ namespace Volo.Abp.MultiTenancy _currentScope = new AsyncLocal(); } - public IDisposable EnterScope(TenantInfo tenantInfo) + public IDisposable EnterScope(TenantInfo tenant) { var parentScope = CurrentScope; - CurrentScope = new TenantScope(tenantInfo); + CurrentScope = new TenantScope(tenant); return new DisposeAction(() => { CurrentScope = parentScope; diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/IMultiTenancyManager.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/IMultiTenancyManager.cs index 3b5f055c77..eab07314e3 100644 --- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/IMultiTenancyManager.cs +++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/IMultiTenancyManager.cs @@ -1,11 +1,13 @@ using System; +using JetBrains.Annotations; namespace Volo.Abp.MultiTenancy { public interface IMultiTenancyManager { + [CanBeNull] TenantInfo CurrentTenant { get; } - IDisposable ChangeTenant(TenantInfo tenantInfo); + IDisposable ChangeTenant([CanBeNull] TenantInfo tenant); } } \ No newline at end of file diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ICurrentTenantResolveContext.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolveContext.cs similarity index 57% rename from src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ICurrentTenantResolveContext.cs rename to src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolveContext.cs index 0830e792d4..ac3c9edb22 100644 --- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ICurrentTenantResolveContext.cs +++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolveContext.cs @@ -1,9 +1,11 @@ +using JetBrains.Annotations; using Volo.Abp.DependencyInjection; namespace Volo.Abp.MultiTenancy { - public interface ICurrentTenantResolveContext : IServiceProviderAccessor + public interface ITenantResolveContext : IServiceProviderAccessor { + [CanBeNull] TenantInfo Tenant { get; set; } bool? Handled { get; set; } diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolver.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolver.cs index 5c3904bebf..843609cbee 100644 --- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolver.cs +++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolver.cs @@ -2,6 +2,6 @@ namespace Volo.Abp.MultiTenancy { public interface ITenantResolver { - void Resolve(ICurrentTenantResolveContext context); + void Resolve(ITenantResolveContext context); } } \ No newline at end of file diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantScopeProvider.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantScopeProvider.cs index ba0e6c35e7..03ecb1965f 100644 --- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantScopeProvider.cs +++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantScopeProvider.cs @@ -8,6 +8,6 @@ namespace Volo.Abp.MultiTenancy [CanBeNull] TenantScope CurrentScope { get; } - IDisposable EnterScope(TenantInfo tenantInfo); + IDisposable EnterScope([CanBeNull] TenantInfo tenant); } } \ No newline at end of file diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs index 6052a699a6..b0a6bff319 100644 --- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs +++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs @@ -6,7 +6,7 @@ using Volo.DependencyInjection; namespace Volo.Abp.MultiTenancy { - public class MultiTenancyManager : IMultiTenancyManager, IScopedDependency + public class MultiTenancyManager : IMultiTenancyManager, ITransientDependency { public TenantInfo CurrentTenant => GetCurrentTenant(); @@ -43,7 +43,7 @@ namespace Volo.Abp.MultiTenancy using (var serviceScope = _serviceProvider.CreateScope()) { - var context = new CurrentTenantResolveContext(serviceScope.ServiceProvider); + var context = new TenantResolveContext(serviceScope.ServiceProvider); foreach (var tenantResolver in _options.TenantResolvers) { @@ -60,9 +60,9 @@ namespace Volo.Abp.MultiTenancy } } - public IDisposable ChangeTenant(TenantInfo tenantInfo) + public IDisposable ChangeTenant(TenantInfo tenant) { - return _tenantScopeProvider.EnterScope(tenantInfo); + return _tenantScopeProvider.EnterScope(tenant); } } } diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/SimpleTenantResolver.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/SimpleTenantResolver.cs index acbe453601..f9329638ba 100644 --- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/SimpleTenantResolver.cs +++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/SimpleTenantResolver.cs @@ -5,16 +5,16 @@ namespace Volo.Abp.MultiTenancy { public class SimpleTenantResolver : ITenantResolver { - private readonly Action _resolveAction; + private readonly Action _resolveAction; - public SimpleTenantResolver([NotNull] Action resolveAction) + public SimpleTenantResolver([NotNull] Action resolveAction) { Check.NotNull(resolveAction, nameof(resolveAction)); _resolveAction = resolveAction; } - public void Resolve(ICurrentTenantResolveContext context) + public void Resolve(ITenantResolveContext context) { _resolveAction(context); } diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentTenantResolveContext.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs similarity index 72% rename from src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentTenantResolveContext.cs rename to src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs index 3f717da1e2..a44e758f54 100644 --- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentTenantResolveContext.cs +++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs @@ -2,7 +2,7 @@ using System; namespace Volo.Abp.MultiTenancy { - public class CurrentTenantResolveContext : ICurrentTenantResolveContext + public class TenantResolveContext : ITenantResolveContext { public IServiceProvider ServiceProvider { get; } @@ -15,7 +15,7 @@ namespace Volo.Abp.MultiTenancy return Handled == true || (Handled == null && Tenant != null); } - public CurrentTenantResolveContext(IServiceProvider serviceProvider) + public TenantResolveContext(IServiceProvider serviceProvider) { ServiceProvider = serviceProvider; } diff --git a/src/Volo.Abp/Volo/Abp/DependencyInjection/IServiceProviderAccessor.cs b/src/Volo.Abp/Volo/Abp/DependencyInjection/IServiceProviderAccessor.cs index 22c4a7d627..151a98df9d 100644 --- a/src/Volo.Abp/Volo/Abp/DependencyInjection/IServiceProviderAccessor.cs +++ b/src/Volo.Abp/Volo/Abp/DependencyInjection/IServiceProviderAccessor.cs @@ -1,9 +1,11 @@ using System; +using JetBrains.Annotations; namespace Volo.Abp.DependencyInjection { public interface IServiceProviderAccessor //TODO: Move to Volo.DependencyInjection package? { + [NotNull] IServiceProvider ServiceProvider { get; } } } \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs index d08fd83894..5555355822 100644 --- a/src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs @@ -57,7 +57,6 @@ namespace Volo.Abp.Domain.Repositories /// /// Primary key of the entity to get /// Entity or null - [CanBeNull] Task FindAsync(TPrimaryKey id); ///