Skip to content

Commit

Permalink
Merge branch 'dev' into cms-kit/pages-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkayilknur committed Feb 19, 2021
2 parents aa14d0c + 999c80a commit 0778532
Show file tree
Hide file tree
Showing 264 changed files with 517,289 additions and 563 deletions.
4 changes: 2 additions & 2 deletions docs/en/UI/Angular/Multi-Tenancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ export const environment = {

> **Important Note:** The `application.baseUrl` and the `{0}` placeholder in the value of the `baseUrl` property are required to be able to get tenant from running URL. Other placeholders in API URLs are optional.
After the configuration above, if your app runs on the `mytenant1.mydomain.com`, the app will get tenant name as **mytenant1** and replace the environment object in `ConfigState` on app initialization as follows:
After the configuration above, if your app runs on the `mytenant1.mydomain.com`, the app will get tenant name as **mytenant1** and replace the environment object in `EnvironmentService` on app initialization as follows:

```js
// environment object in ConfigState
// environment object in EnvironmentService

{
//...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUglify" Version="1.11.4" />
<PackageReference Include="NUglify" Version="1.13.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionRepositoryExtensions
{
public static IServiceCollection AddDefaultRepository(this IServiceCollection services, Type entityType, Type repositoryImplementationType)
public static IServiceCollection AddDefaultRepository(
this IServiceCollection services,
Type entityType,
Type repositoryImplementationType,
bool replaceExisting = false)
{
//IReadOnlyBasicRepository<TEntity>
var readOnlyBasicRepositoryInterface = typeof(IReadOnlyBasicRepository<>).MakeGenericType(entityType);
if (readOnlyBasicRepositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(readOnlyBasicRepositoryInterface, repositoryImplementationType);
RegisterService(services, readOnlyBasicRepositoryInterface, repositoryImplementationType, replaceExisting);

//IReadOnlyRepository<TEntity>
var readOnlyRepositoryInterface = typeof(IReadOnlyRepository<>).MakeGenericType(entityType);
if (readOnlyRepositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(readOnlyRepositoryInterface, repositoryImplementationType);
RegisterService(services, readOnlyRepositoryInterface, repositoryImplementationType, replaceExisting);
}

//IBasicRepository<TEntity>
var basicRepositoryInterface = typeof(IBasicRepository<>).MakeGenericType(entityType);
if (basicRepositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(basicRepositoryInterface, repositoryImplementationType);
RegisterService(services, basicRepositoryInterface, repositoryImplementationType, replaceExisting);

//IRepository<TEntity>
var repositoryInterface = typeof(IRepository<>).MakeGenericType(entityType);
if (repositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(repositoryInterface, repositoryImplementationType);
RegisterService(services, repositoryInterface, repositoryImplementationType, replaceExisting);
}
}
}
Expand All @@ -44,32 +48,48 @@ public static IServiceCollection AddDefaultRepository(this IServiceCollection se
var readOnlyBasicRepositoryInterfaceWithPk = typeof(IReadOnlyBasicRepository<,>).MakeGenericType(entityType, primaryKeyType);
if (readOnlyBasicRepositoryInterfaceWithPk.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(readOnlyBasicRepositoryInterfaceWithPk, repositoryImplementationType);
RegisterService(services, readOnlyBasicRepositoryInterfaceWithPk, repositoryImplementationType, replaceExisting);

//IReadOnlyRepository<TEntity, TKey>
var readOnlyRepositoryInterfaceWithPk = typeof(IReadOnlyRepository<,>).MakeGenericType(entityType, primaryKeyType);
if (readOnlyRepositoryInterfaceWithPk.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(readOnlyRepositoryInterfaceWithPk, repositoryImplementationType);
RegisterService(services, readOnlyRepositoryInterfaceWithPk, repositoryImplementationType, replaceExisting);
}

//IBasicRepository<TEntity, TKey>
var basicRepositoryInterfaceWithPk = typeof(IBasicRepository<,>).MakeGenericType(entityType, primaryKeyType);
if (basicRepositoryInterfaceWithPk.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(basicRepositoryInterfaceWithPk, repositoryImplementationType);
RegisterService(services, basicRepositoryInterfaceWithPk, repositoryImplementationType, replaceExisting);

//IRepository<TEntity, TKey>
var repositoryInterfaceWithPk = typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType);
if (repositoryInterfaceWithPk.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(repositoryInterfaceWithPk, repositoryImplementationType);
RegisterService(services, repositoryInterfaceWithPk, repositoryImplementationType, replaceExisting);
}
}
}
}

return services;
}

private static void RegisterService(
IServiceCollection services,
Type serviceType,
Type implementationType,
bool replaceExisting)
{
if (replaceExisting)
{
services.Replace(ServiceDescriptor.Transient(serviceType, implementationType));
}
else
{
services.TryAddTransient(serviceType, implementationType);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Volo.Abp.Domain.Repositories
{
/* Repositories are not injected by class by default.
* This class specializes repository registration to apply this rule.
*/
public class AbpRepositoryConventionalRegistrar : DefaultConventionalRegistrar
{
public static bool ExposeRepositoryClasses { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public virtual void AddRepositories()
{
foreach (var customRepository in Options.CustomRepositories)
{
Options.Services.AddDefaultRepository(customRepository.Key, customRepository.Value);
Options.Services.AddDefaultRepository(customRepository.Key, customRepository.Value, replaceExisting: true);
}

if (Options.RegisterDefaultRepositories)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<!--<PackageReference Include="Oracle.EntityFrameworkCore" Version="3.19.80" />-->
<PackageReference Include="Oracle.EntityFrameworkCore" Version="5.21.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
// using JetBrains.Annotations;
// using Microsoft.EntityFrameworkCore;
// using System;
// using Oracle.EntityFrameworkCore.Infrastructure;
// using Volo.Abp.EntityFrameworkCore.DependencyInjection;
//
// namespace Volo.Abp.EntityFrameworkCore
// {
// public static class AbpDbContextConfigurationContextOracleExtensions
// {
// public static DbContextOptionsBuilder UseOracle(
// [NotNull] this AbpDbContextConfigurationContext context,
// [CanBeNull] Action<OracleDbContextOptionsBuilder> oracleOptionsAction = null)
// {
// TODO: UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery);
// if (context.ExistingConnection != null)
// {
// return context.DbContextOptions.UseOracle(context.ExistingConnection, oracleOptionsAction);
// }
// else
// {
// return context.DbContextOptions.UseOracle(context.ConnectionString, oracleOptionsAction);
// }
// }
// }
// }
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using System;
using Oracle.EntityFrameworkCore.Infrastructure;
using Volo.Abp.EntityFrameworkCore.DependencyInjection;

namespace Volo.Abp.EntityFrameworkCore
{
public static class AbpDbContextConfigurationContextOracleExtensions
{
public static DbContextOptionsBuilder UseOracle(
[NotNull] this AbpDbContextConfigurationContext context,
[CanBeNull] Action<OracleDbContextOptionsBuilder> oracleOptionsAction = null)
{
if (context.ExistingConnection != null)
{
return context.DbContextOptions.UseOracle(context.ExistingConnection, optionsBuilder =>
{
optionsBuilder.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery);
oracleOptionsAction?.Invoke(optionsBuilder);
});
}
else
{
return context.DbContextOptions.UseOracle(context.ConnectionString, optionsBuilder =>
{
optionsBuilder.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery);
oracleOptionsAction?.Invoke(optionsBuilder);
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// using JetBrains.Annotations;
// using System;
// using Oracle.EntityFrameworkCore.Infrastructure;
//
// namespace Volo.Abp.EntityFrameworkCore
// {
// public static class AbpDbContextOptionsOracleExtensions
// {
// public static void UseOracle(
// [NotNull] this AbpDbContextOptions options,
// [CanBeNull] Action<OracleDbContextOptionsBuilder> oracleOptionsAction = null)
// {
// options.Configure(context =>
// {
// context.UseOracle(oracleOptionsAction);
// });
// }
//
// public static void UseOracle<TDbContext>(
// [NotNull] this AbpDbContextOptions options,
// [CanBeNull] Action<OracleDbContextOptionsBuilder> oracleOptionsAction = null)
// where TDbContext : AbpDbContext<TDbContext>
// {
// options.Configure<TDbContext>(context =>
// {
// context.UseOracle(oracleOptionsAction);
// });
// }
// }
// }
using JetBrains.Annotations;
using System;
using Oracle.EntityFrameworkCore.Infrastructure;

namespace Volo.Abp.EntityFrameworkCore
{
public static class AbpDbContextOptionsOracleExtensions
{
public static void UseOracle(
[NotNull] this AbpDbContextOptions options,
[CanBeNull] Action<OracleDbContextOptionsBuilder> oracleOptionsAction = null)
{
options.Configure(context =>
{
context.UseOracle(oracleOptionsAction);
});
}

public static void UseOracle<TDbContext>(
[NotNull] this AbpDbContextOptions options,
[CanBeNull] Action<OracleDbContextOptionsBuilder> oracleOptionsAction = null)
where TDbContext : AbpDbContext<TDbContext>
{
options.Configure<TDbContext>(context =>
{
context.UseOracle(oracleOptionsAction);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
// using Volo.Abp.Guids;
// using Volo.Abp.Modularity;
//
// namespace Volo.Abp.EntityFrameworkCore.Oracle
// {
// [DependsOn(
// typeof(AbpEntityFrameworkCoreModule)
// )]
// public class AbpEntityFrameworkCoreOracleModule : AbpModule
// {
// public override void ConfigureServices(ServiceConfigurationContext context)
// {
// Configure<AbpSequentialGuidGeneratorOptions>(options =>
// {
// if (options.DefaultSequentialGuidType == null)
// {
// options.DefaultSequentialGuidType = SequentialGuidType.SequentialAsBinary;
// }
// });
// }
// }
// }
using Volo.Abp.Guids;
using Volo.Abp.Modularity;

namespace Volo.Abp.EntityFrameworkCore.Oracle
{
[DependsOn(typeof(AbpEntityFrameworkCoreModule))]
public class AbpEntityFrameworkCoreOracleModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpSequentialGuidGeneratorOptions>(options =>
{
if (options.DefaultSequentialGuidType == null)
{
options.DefaultSequentialGuidType = SequentialGuidType.SequentialAsBinary;
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ public static IServiceCollection AddAbpDbContext<TDbContext>(

foreach (var dbContextType in options.ReplacedDbContextTypes)
{
services.Replace(ServiceDescriptor.Transient(dbContextType, typeof(TDbContext)));
services.Replace(
ServiceDescriptor.Transient(
dbContextType,
sp => sp.GetRequiredService(typeof(TDbContext))
)
);

services.Configure<AbpDbContextOptions>(opts =>
{
opts.DbContextReplacements[dbContextType] = typeof(TDbContext);
});
}

new EfCoreRepositoryRegistrar(options).AddRepositories();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand All @@ -8,6 +9,7 @@
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Volo.Abp.EntityFrameworkCore")]
[assembly: AssemblyTrademark("")]
[assembly: InternalsVisibleTo("Volo.Abp.EntityFrameworkCore.Tests")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ namespace Volo.Abp.EntityFrameworkCore
{
public class AbpDbContextOptions
{
internal List<Action<AbpDbContextConfigurationContext>> DefaultPreConfigureActions { get; set; }
internal List<Action<AbpDbContextConfigurationContext>> DefaultPreConfigureActions { get; }

internal Action<AbpDbContextConfigurationContext> DefaultConfigureAction { get; set; }

internal Dictionary<Type, List<object>> PreConfigureActions { get; set; }
internal Dictionary<Type, List<object>> PreConfigureActions { get; }

internal Dictionary<Type, object> ConfigureActions { get; set; }
internal Dictionary<Type, object> ConfigureActions { get; }

internal Dictionary<Type, Type> DbContextReplacements { get; }

public AbpDbContextOptions()
{
DefaultPreConfigureActions = new List<Action<AbpDbContextConfigurationContext>>();
PreConfigureActions = new Dictionary<Type, List<object>>();
ConfigureActions = new Dictionary<Type, object>();
DbContextReplacements = new Dictionary<Type, Type>();
}

public void PreConfigure([NotNull] Action<AbpDbContextConfigurationContext> action)
Expand Down Expand Up @@ -57,5 +60,29 @@ public void Configure<TDbContext>([NotNull] Action<AbpDbContextConfigurationCont

ConfigureActions[typeof(TDbContext)] = action;
}

internal Type GetReplacedTypeOrSelf(Type dbContextType)
{
var replacementType = dbContextType;
while (true)
{
if (DbContextReplacements.TryGetValue(replacementType, out var foundType))
{
if (foundType == dbContextType)
{
throw new AbpException(
"Circular DbContext replacement found for " +
dbContextType.AssemblyQualifiedName
);
}

replacementType = foundType;
}
else
{
return replacementType;
}
}
}
}
}
Loading

0 comments on commit 0778532

Please sign in to comment.