diff --git a/extensions/Squidex.Extensions/Squidex.Extensions.csproj b/extensions/Squidex.Extensions/Squidex.Extensions.csproj
index 0940d8a2a..7b29d3dba 100644
--- a/extensions/Squidex.Extensions/Squidex.Extensions.csproj
+++ b/extensions/Squidex.Extensions/Squidex.Extensions.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj b/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj
index 71cb09f85..70163bdfd 100644
--- a/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj
+++ b/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj
@@ -9,7 +9,7 @@
True
-
+
all
runtime; build; native; contentfiles; analyzers
diff --git a/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj b/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj
index 333692707..20dfa8cb5 100644
--- a/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj
+++ b/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj
@@ -17,7 +17,7 @@
-
+
diff --git a/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj b/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj
index 46f190489..cc01356e9 100644
--- a/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj
+++ b/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj
@@ -25,7 +25,7 @@
runtime; build; native; contentfiles; analyzers
-
+
diff --git a/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj b/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj
index 65c44bd59..3ebd7ece0 100644
--- a/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj
+++ b/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj b/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj
index 5351ea162..b2bd38afe 100644
--- a/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj
+++ b/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/src/Squidex.Infrastructure/DependencyInjection/DependencyInjectionExtensions.cs b/src/Squidex.Infrastructure/DependencyInjection/DependencyInjectionExtensions.cs
index 9ee638ac0..c89078eb1 100644
--- a/src/Squidex.Infrastructure/DependencyInjection/DependencyInjectionExtensions.cs
+++ b/src/Squidex.Infrastructure/DependencyInjection/DependencyInjectionExtensions.cs
@@ -14,13 +14,29 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class DependencyInjectionExtensions
{
+ public delegate void Registrator(Type serviceType, Func implementationFactory);
+
public sealed class InterfaceRegistrator
{
- private readonly IServiceCollection services;
+ private readonly Registrator register;
+ private readonly Registrator registerOptional;
- public InterfaceRegistrator(IServiceCollection services)
+ public InterfaceRegistrator(Registrator register, Registrator registerOptional)
{
- this.services = services;
+ this.register = register;
+ this.registerOptional = registerOptional;
+
+ var interfaces = typeof(T).GetInterfaces();
+
+ if (interfaces.Contains(typeof(IInitializable)))
+ {
+ register(typeof(IInitializable), c => c.GetRequiredService());
+ }
+
+ if (interfaces.Contains(typeof(IBackgroundProcess)))
+ {
+ register(typeof(IBackgroundProcess), c => c.GetRequiredService());
+ }
}
public InterfaceRegistrator AsSelf()
@@ -32,7 +48,7 @@ namespace Microsoft.Extensions.DependencyInjection
{
if (typeof(TInterface) != typeof(T))
{
- services.TryAddSingleton(typeof(TInterface), c => c.GetRequiredService());
+ registerOptional(typeof(TInterface), c => c.GetRequiredService());
}
return this;
@@ -42,7 +58,7 @@ namespace Microsoft.Extensions.DependencyInjection
{
if (typeof(TInterface) != typeof(T))
{
- services.AddSingleton(typeof(TInterface), c => c.GetRequiredService());
+ register(typeof(TInterface), c => c.GetRequiredService());
}
return this;
@@ -53,47 +69,28 @@ namespace Microsoft.Extensions.DependencyInjection
{
services.AddTransient(typeof(T), factory);
- return new InterfaceRegistrator(services);
+ return new InterfaceRegistrator((t, f) => services.AddTransient(t, f), (t, f) => services.TryAddTransient(t, f));
}
public static InterfaceRegistrator AddTransientAs(this IServiceCollection services) where T : class
{
services.AddTransient();
- return new InterfaceRegistrator(services);
+ return new InterfaceRegistrator((t, f) => services.AddTransient(t, f), (t, f) => services.TryAddTransient(t, f));
}
public static InterfaceRegistrator AddSingletonAs(this IServiceCollection services, Func factory) where T : class
{
services.AddSingleton(typeof(T), factory);
- RegisterDefaults(services);
-
- return new InterfaceRegistrator(services);
+ return new InterfaceRegistrator((t, f) => services.AddSingleton(t, f), (t, f) => services.TryAddSingleton(t, f));
}
public static InterfaceRegistrator AddSingletonAs(this IServiceCollection services) where T : class
{
services.AddSingleton();
- RegisterDefaults(services);
-
- return new InterfaceRegistrator(services);
- }
-
- private static void RegisterDefaults(IServiceCollection services) where T : class
- {
- var interfaces = typeof(T).GetInterfaces();
-
- if (interfaces.Contains(typeof(IInitializable)))
- {
- services.AddSingleton(typeof(IInitializable), c => c.GetRequiredService());
- }
-
- if (interfaces.Contains(typeof(IBackgroundProcess)))
- {
- services.AddSingleton(typeof(IBackgroundProcess), c => c.GetRequiredService());
- }
+ return new InterfaceRegistrator((t, f) => services.AddSingleton(t, f), (t, f) => services.TryAddSingleton(t, f));
}
}
}
diff --git a/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj b/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj
index 2ac2b92d0..a57b8836d 100644
--- a/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj
+++ b/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj
@@ -20,14 +20,14 @@
-
+
-
+
diff --git a/src/Squidex/Squidex.csproj b/src/Squidex/Squidex.csproj
index f7c33f443..79983c5dc 100644
--- a/src/Squidex/Squidex.csproj
+++ b/src/Squidex/Squidex.csproj
@@ -68,15 +68,15 @@
-
-
+
+
-
-
+
+
-
-
+
+
diff --git a/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj b/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj
index 4332f6cfe..75c5e5e66 100644
--- a/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj
+++ b/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj
@@ -15,7 +15,7 @@
-
+