diff --git a/src/CatLib.Core.Tests/CatLib/ApplicationTests.cs b/src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
index f36c8e7..408f88f 100644
--- a/src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
+++ b/src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
@@ -43,16 +43,8 @@ public void Register()
}
}
- public class TestServiceProvider : IServiceProvider, IServiceProviderType
+ public class TestServiceProvider : IServiceProvider
{
- ///
- /// 提供者基础类型.
- ///
- public Type BaseType
- {
- get { return typeof(TestBaseServiceProvider); }
- }
-
///
/// 服务提供者初始化.
///
@@ -86,27 +78,6 @@ public void RepeatInitTest()
app.Init();
}
- [TestMethod]
- public void TestBaseTypeProvider()
- {
- var app = new Application();
- app.Bootstrap();
- app.Register(new TestServiceProvider());
-
- RuntimeException ex = null;
- try
- {
- app.Init();
- }
- catch (RuntimeException e)
- {
- ex = e;
- }
-
- Assert.AreNotEqual(null, ex);
- Assert.AreEqual("TestServiceProvider", ex.Message);
- }
-
///
/// 未经引导的初始化.
///
@@ -311,11 +282,12 @@ public void RegisteredIllegalType()
public void RepeatRegister()
{
var app = MakeApplication();
- app.Register(new ProviderTest1());
+ var provider = new ProviderTest1();
+ app.Register(provider);
ExceptionAssert.Throws(() =>
{
- app.Register(new ProviderTest1());
+ app.Register(provider);
});
}
@@ -399,11 +371,12 @@ public void TestRepeatRegister()
});
app.Bootstrap();
- app.Register(new ProviderTest1());
+ var provider = new ProviderTest1();
+ app.Register(provider);
ExceptionAssert.Throws(() =>
{
- app.Register(new ProviderTest1());
+ app.Register(provider);
});
}
diff --git a/src/CatLib.Core/CatLib/Application.cs b/src/CatLib.Core/CatLib/Application.cs
index c242eba..30df4b9 100644
--- a/src/CatLib.Core/CatLib/Application.cs
+++ b/src/CatLib.Core/CatLib/Application.cs
@@ -32,15 +32,10 @@ public class Application : CatLibContainer, IApplication
///
private static string version;
- ///
- /// All of the registered service providers.
- ///
- private readonly List serviceProviders;
-
///
/// The types of the loaded service providers.
///
- private readonly HashSet loadedProviders;
+ private readonly List loadedProviders;
///
/// The main thread id.
@@ -79,8 +74,7 @@ public class Application : CatLibContainer, IApplication
/// True if sets the instance to facade.
public Application(bool global = true)
{
- serviceProviders = new List();
- loadedProviders = new HashSet();
+ loadedProviders = new List();
mainThreadId = Thread.CurrentThread.ManagedThreadId;
RegisterBaseBindings();
@@ -289,7 +283,7 @@ public virtual void Init()
Dispatch(new BeforeInitEventArgs(this));
Process = StartProcess.Initing;
- foreach (var provider in serviceProviders)
+ foreach (var provider in loadedProviders)
{
InitProvider(provider);
}
@@ -314,7 +308,7 @@ public virtual void Register(IServiceProvider provider, bool force = false)
throw new LogicException($"Provider [{provider.GetType()}] is already register.");
}
- loadedProviders.Remove(GetProviderBaseType(provider));
+ loadedProviders.Remove(provider);
}
if (Process == StartProcess.Initing)
@@ -344,8 +338,7 @@ public virtual void Register(IServiceProvider provider, bool force = false)
registering = false;
}
- serviceProviders.Add(provider);
- loadedProviders.Add(GetProviderBaseType(provider));
+ loadedProviders.Add(provider);
if (inited)
{
@@ -357,7 +350,7 @@ public virtual void Register(IServiceProvider provider, bool force = false)
public bool IsRegistered(IServiceProvider provider)
{
Guard.Requires(provider != null);
- return loadedProviders.Contains(GetProviderBaseType(provider));
+ return loadedProviders.Contains(provider);
}
///
@@ -413,16 +406,6 @@ protected override void GuardConstruct(string method)
base.GuardConstruct(method);
}
- ///
- /// Get the base type from service provider.
- ///
- /// The service provider.
- /// Base type for service provider.
- private static Type GetProviderBaseType(IServiceProvider provider)
- {
- return !(provider is IServiceProviderType providerType) ? provider.GetType() : providerType.BaseType;
- }
-
///
/// Register the core service aliases.
///
diff --git a/src/CatLib.Core/CatLib/IServiceProviderType.cs b/src/CatLib.Core/CatLib/IServiceProviderType.cs
deleted file mode 100644
index 5c7da15..0000000
--- a/src/CatLib.Core/CatLib/IServiceProviderType.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * This file is part of the CatLib package.
- *
- * (c) CatLib
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * Document: https://catlib.io/
- */
-
-using System;
-
-namespace CatLib
-{
- ///
- /// Allow current service providers to be treated as specified service providers.
- ///
- public interface IServiceProviderType
- {
- ///
- /// Gets the Type to be treated as specified service providers.
- ///
- Type BaseType { get; }
- }
-}