mirror of
https://github.com/AlexMacocian/Slim.git
synced 2026-07-15 15:19:59 +00:00
Scoped servicemanager should have own lists
This commit is contained in:
@@ -458,5 +458,21 @@ namespace Slim.Tests
|
||||
dependentService1.Should().NotBeNull();
|
||||
dependentService2.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ScopedManagerShouldHaveItsOwnLists()
|
||||
{
|
||||
var di = new ServiceManager();
|
||||
di.RegisterSingleton<IIndependentService, IndependentService>();
|
||||
var scopedDi = di.CreateScope();
|
||||
|
||||
di.RegisterSingleton<IDependentService, DependentService>();
|
||||
scopedDi.As<IServiceManager>().RegisterSingleton<IDependentService, DependentService>();
|
||||
|
||||
var dependentService1 = di.GetService<IDependentService>();
|
||||
var dependentService2 = scopedDi.GetService<IDependentService>();
|
||||
|
||||
dependentService1.Should().NotBe(dependentService2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-6
@@ -346,12 +346,7 @@ namespace Slim
|
||||
/// <returns>Scoped <see cref="IServiceProvider"/>.</returns>
|
||||
public IServiceProvider CreateScope()
|
||||
{
|
||||
return new ServiceManager(
|
||||
interfaceMapping: this.InterfaceMapping,
|
||||
factories: this.Factories,
|
||||
exceptionHandlers: this.ExceptionHandlers,
|
||||
resolvers: this.Resolvers,
|
||||
singletons: this.GetSingletons());
|
||||
return this.CreateScopeInner();
|
||||
}
|
||||
/// <summary>
|
||||
/// Resolves and returns the required service.
|
||||
@@ -686,5 +681,14 @@ namespace Slim
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
private ServiceManager CreateScopeInner()
|
||||
{
|
||||
var interfaceMapping = new Dictionary<Type, (Type, Lifetime)>(this.InterfaceMapping);
|
||||
var factories = new Dictionary<Type, Delegate>(this.Factories);
|
||||
var exceptionHandlers = new Dictionary<Type, Delegate>(this.ExceptionHandlers);
|
||||
var resolvers = new List<IDependencyResolver>(this.Resolvers);
|
||||
var singletons = this.GetSingletons();
|
||||
return new ServiceManager(interfaceMapping, singletons, factories, exceptionHandlers, resolvers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -8,10 +8,10 @@
|
||||
<Company />
|
||||
<Product></Product>
|
||||
<Description>Service lifetime management and dependency injection framework.</Description>
|
||||
<AssemblyVersion>1.4.1.0</AssemblyVersion>
|
||||
<FileVersion>1.4.1.0</FileVersion>
|
||||
<AssemblyVersion>1.4.2.0</AssemblyVersion>
|
||||
<FileVersion>1.4.2.0</FileVersion>
|
||||
<PackageProjectUrl>https://github.com/AlexMacocian/Slim</PackageProjectUrl>
|
||||
<Version>1.4.1</Version>
|
||||
<Version>1.4.2</Version>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
|
||||
Reference in New Issue
Block a user