Browse Source

Revised codebase.

pull/81/head
Halil İbrahim Kalkan 10 years ago
parent
commit
85fd510852
  1. 2
      src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs
  2. 2
      src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpDbContextConfigurationContext.cs
  3. 4
      src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs
  4. 5
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs
  5. 3
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  6. 3
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs
  7. 4
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs
  8. 4
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/IDbContextProvider.cs
  9. 26
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/DbContextDatabaseApi.cs
  10. 26
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs
  11. 6
      src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/AsyncLocalTenantScopeProvider.cs
  12. 4
      src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/IMultiTenancyManager.cs
  13. 4
      src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolveContext.cs
  14. 2
      src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolver.cs
  15. 2
      src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantScopeProvider.cs
  16. 8
      src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs
  17. 6
      src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/SimpleTenantResolver.cs
  18. 4
      src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs
  19. 2
      src/Volo.Abp/Volo/Abp/DependencyInjection/IServiceProviderAccessor.cs
  20. 1
      src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs

2
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 const string TenantIdKey = "__tenantId";
public void Resolve(ICurrentTenantResolveContext context) public void Resolve(ITenantResolveContext context)
{ {
var httpContext = context.GetHttpContext(); var httpContext = context.GetHttpContext();
if (httpContext == null) if (httpContext == null)

2
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 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) public AbpDbContextConfigurationContext(string connectionString, [CanBeNull] string moduleName)
{ {

4
src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs

@ -1,8 +1,8 @@
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Repositories.EntityFrameworkCore;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
@ -12,7 +12,7 @@ namespace Microsoft.Extensions.DependencyInjection
this IServiceCollection services) this IServiceCollection services)
where TDbContext : AbpDbContext<TDbContext> where TDbContext : AbpDbContext<TDbContext>
{ {
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() .AddMemoryCache()
.AddLogging(); .AddLogging();

5
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs → src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EfCoreRepositoryExtensions.cs

@ -1,10 +1,9 @@
using System; using System;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.Repositories.EntityFrameworkCore;
namespace Volo.Abp.Repositories namespace Volo.Abp.Domain.Repositories
{ {
public static class EfCoreRepositoryExtensions public static class EfCoreRepositoryExtensions
{ {

3
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs → src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs

@ -3,10 +3,9 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.Repositories.EntityFrameworkCore namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
{ {
public class EfCoreRepository<TDbContext, TEntity, TPrimaryKey> : QueryableRepositoryBase<TEntity, TPrimaryKey>, IEfCoreRepository<TEntity, TPrimaryKey> public class EfCoreRepository<TDbContext, TEntity, TPrimaryKey> : QueryableRepositoryBase<TEntity, TPrimaryKey>, IEfCoreRepository<TEntity, TPrimaryKey>
where TDbContext : AbpDbContext<TDbContext> where TDbContext : AbpDbContext<TDbContext>

3
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs → src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/IEfCoreRepository.cs

@ -1,8 +1,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.Repositories.EntityFrameworkCore namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
{ {
public interface IEfCoreRepository<TEntity, TPrimaryKey> : IQueryableRepository<TEntity, TPrimaryKey> public interface IEfCoreRepository<TEntity, TPrimaryKey> : IQueryableRepository<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>

4
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs

@ -1,7 +1,7 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Repositories.EntityFrameworkCore; using Volo.Abp.Uow.EntityFrameworkCore;
namespace Volo.Abp.EntityFrameworkCore namespace Volo.Abp.EntityFrameworkCore
{ {
@ -9,8 +9,8 @@ namespace Volo.Abp.EntityFrameworkCore
{ {
public override void ConfigureServices(IServiceCollection services) public override void ConfigureServices(IServiceCollection services)
{ {
//TODO: This will be changed!
services.TryAddTransient(typeof(IDbContextProvider<>), typeof(UnitOfWorkDbContextProvider<>)); services.TryAddTransient(typeof(IDbContextProvider<>), typeof(UnitOfWorkDbContextProvider<>));
services.AddAssemblyOf<AbpEntityFrameworkCoreModule>();
} }
} }
} }

4
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IDbContextProvider.cs → src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/IDbContextProvider.cs

@ -1,6 +1,4 @@
using Volo.Abp.EntityFrameworkCore; namespace Volo.Abp.EntityFrameworkCore
namespace Volo.Abp.Repositories.EntityFrameworkCore
{ {
public interface IDbContextProvider<out TDbContext> public interface IDbContextProvider<out TDbContext>
where TDbContext : AbpDbContext<TDbContext> where TDbContext : AbpDbContext<TDbContext>

26
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<TDbContext> : IDatabaseApi
where TDbContext : AbpDbContext<TDbContext>
{
public TDbContext DbContext { get; }
public DbContextDatabaseApi(TDbContext dbContext)
{
DbContext = dbContext;
}
public Task SaveChangesAsync()
{
return DbContext.SaveChangesAsync();
}
public Task CommitAsync()
{
return DbContext.SaveChangesAsync();
}
}
}

26
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs → 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 Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Uow;
namespace Volo.Abp.Repositories.EntityFrameworkCore namespace Volo.Abp.Uow.EntityFrameworkCore
{ {
public class UnitOfWorkDbContextProvider<TDbContext> : IDbContextProvider<TDbContext> public class UnitOfWorkDbContextProvider<TDbContext> : IDbContextProvider<TDbContext>
where TDbContext : AbpDbContext<TDbContext> where TDbContext : AbpDbContext<TDbContext>
@ -41,25 +38,4 @@ namespace Volo.Abp.Repositories.EntityFrameworkCore
return ((DbContextDatabaseApi<TDbContext>)databaseApi).DbContext; return ((DbContextDatabaseApi<TDbContext>)databaseApi).DbContext;
} }
} }
public class DbContextDatabaseApi<TDbContext> : IDatabaseApi
where TDbContext : AbpDbContext<TDbContext>
{
public TDbContext DbContext { get; }
public DbContextDatabaseApi(TDbContext dbContext)
{
DbContext = dbContext;
}
public Task SaveChangesAsync()
{
return DbContext.SaveChangesAsync();
}
public Task CommitAsync()
{
return DbContext.SaveChangesAsync();
}
}
} }

6
src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/AsyncLocalTenantScopeProvider.cs

@ -4,7 +4,7 @@ using Volo.DependencyInjection;
namespace Volo.Abp.MultiTenancy namespace Volo.Abp.MultiTenancy
{ {
public class AsyncLocalTenantScopeProvider : ITenantScopeProvider, IScopedDependency public class AsyncLocalTenantScopeProvider : ITenantScopeProvider, ISingletonDependency
{ {
public TenantScope CurrentScope public TenantScope CurrentScope
{ {
@ -19,10 +19,10 @@ namespace Volo.Abp.MultiTenancy
_currentScope = new AsyncLocal<TenantScope>(); _currentScope = new AsyncLocal<TenantScope>();
} }
public IDisposable EnterScope(TenantInfo tenantInfo) public IDisposable EnterScope(TenantInfo tenant)
{ {
var parentScope = CurrentScope; var parentScope = CurrentScope;
CurrentScope = new TenantScope(tenantInfo); CurrentScope = new TenantScope(tenant);
return new DisposeAction(() => return new DisposeAction(() =>
{ {
CurrentScope = parentScope; CurrentScope = parentScope;

4
src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/IMultiTenancyManager.cs

@ -1,11 +1,13 @@
using System; using System;
using JetBrains.Annotations;
namespace Volo.Abp.MultiTenancy namespace Volo.Abp.MultiTenancy
{ {
public interface IMultiTenancyManager public interface IMultiTenancyManager
{ {
[CanBeNull]
TenantInfo CurrentTenant { get; } TenantInfo CurrentTenant { get; }
IDisposable ChangeTenant(TenantInfo tenantInfo); IDisposable ChangeTenant([CanBeNull] TenantInfo tenant);
} }
} }

4
src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ICurrentTenantResolveContext.cs → src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolveContext.cs

@ -1,9 +1,11 @@
using JetBrains.Annotations;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.MultiTenancy namespace Volo.Abp.MultiTenancy
{ {
public interface ICurrentTenantResolveContext : IServiceProviderAccessor public interface ITenantResolveContext : IServiceProviderAccessor
{ {
[CanBeNull]
TenantInfo Tenant { get; set; } TenantInfo Tenant { get; set; }
bool? Handled { get; set; } bool? Handled { get; set; }

2
src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantResolver.cs

@ -2,6 +2,6 @@ namespace Volo.Abp.MultiTenancy
{ {
public interface ITenantResolver public interface ITenantResolver
{ {
void Resolve(ICurrentTenantResolveContext context); void Resolve(ITenantResolveContext context);
} }
} }

2
src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantScopeProvider.cs

@ -8,6 +8,6 @@ namespace Volo.Abp.MultiTenancy
[CanBeNull] [CanBeNull]
TenantScope CurrentScope { get; } TenantScope CurrentScope { get; }
IDisposable EnterScope(TenantInfo tenantInfo); IDisposable EnterScope([CanBeNull] TenantInfo tenant);
} }
} }

8
src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs

@ -6,7 +6,7 @@ using Volo.DependencyInjection;
namespace Volo.Abp.MultiTenancy namespace Volo.Abp.MultiTenancy
{ {
public class MultiTenancyManager : IMultiTenancyManager, IScopedDependency public class MultiTenancyManager : IMultiTenancyManager, ITransientDependency
{ {
public TenantInfo CurrentTenant => GetCurrentTenant(); public TenantInfo CurrentTenant => GetCurrentTenant();
@ -43,7 +43,7 @@ namespace Volo.Abp.MultiTenancy
using (var serviceScope = _serviceProvider.CreateScope()) using (var serviceScope = _serviceProvider.CreateScope())
{ {
var context = new CurrentTenantResolveContext(serviceScope.ServiceProvider); var context = new TenantResolveContext(serviceScope.ServiceProvider);
foreach (var tenantResolver in _options.TenantResolvers) 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);
} }
} }
} }

6
src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/SimpleTenantResolver.cs

@ -5,16 +5,16 @@ namespace Volo.Abp.MultiTenancy
{ {
public class SimpleTenantResolver : ITenantResolver public class SimpleTenantResolver : ITenantResolver
{ {
private readonly Action<ICurrentTenantResolveContext> _resolveAction; private readonly Action<ITenantResolveContext> _resolveAction;
public SimpleTenantResolver([NotNull] Action<ICurrentTenantResolveContext> resolveAction) public SimpleTenantResolver([NotNull] Action<ITenantResolveContext> resolveAction)
{ {
Check.NotNull(resolveAction, nameof(resolveAction)); Check.NotNull(resolveAction, nameof(resolveAction));
_resolveAction = resolveAction; _resolveAction = resolveAction;
} }
public void Resolve(ICurrentTenantResolveContext context) public void Resolve(ITenantResolveContext context)
{ {
_resolveAction(context); _resolveAction(context);
} }

4
src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentTenantResolveContext.cs → src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs

@ -2,7 +2,7 @@ using System;
namespace Volo.Abp.MultiTenancy namespace Volo.Abp.MultiTenancy
{ {
public class CurrentTenantResolveContext : ICurrentTenantResolveContext public class TenantResolveContext : ITenantResolveContext
{ {
public IServiceProvider ServiceProvider { get; } public IServiceProvider ServiceProvider { get; }
@ -15,7 +15,7 @@ namespace Volo.Abp.MultiTenancy
return Handled == true || (Handled == null && Tenant != null); return Handled == true || (Handled == null && Tenant != null);
} }
public CurrentTenantResolveContext(IServiceProvider serviceProvider) public TenantResolveContext(IServiceProvider serviceProvider)
{ {
ServiceProvider = serviceProvider; ServiceProvider = serviceProvider;
} }

2
src/Volo.Abp/Volo/Abp/DependencyInjection/IServiceProviderAccessor.cs

@ -1,9 +1,11 @@
using System; using System;
using JetBrains.Annotations;
namespace Volo.Abp.DependencyInjection namespace Volo.Abp.DependencyInjection
{ {
public interface IServiceProviderAccessor //TODO: Move to Volo.DependencyInjection package? public interface IServiceProviderAccessor //TODO: Move to Volo.DependencyInjection package?
{ {
[NotNull]
IServiceProvider ServiceProvider { get; } IServiceProvider ServiceProvider { get; }
} }
} }

1
src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs

@ -57,7 +57,6 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="id">Primary key of the entity to get</param> /// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity or null</returns> /// <returns>Entity or null</returns>
[CanBeNull]
Task<TEntity> FindAsync(TPrimaryKey id); Task<TEntity> FindAsync(TPrimaryKey id);
/// <summary> /// <summary>

Loading…
Cancel
Save