Compare commits
3 Commits
d87f36898b
...
5567f6731b
| Author | SHA1 | Date | |
|---|---|---|---|
| 5567f6731b | |||
| fc297d92fa | |||
| 50a056d110 |
@@ -16,9 +16,9 @@
|
|||||||
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
||||||
<PackAsTool>False</PackAsTool>
|
<PackAsTool>False</PackAsTool>
|
||||||
<PackageIcon>core_icon.png</PackageIcon>
|
<PackageIcon>core_icon.png</PackageIcon>
|
||||||
<Version>4.2.0</Version>
|
<Version>4.3.0</Version>
|
||||||
<AssemblyVersion>4.2.0</AssemblyVersion>
|
<AssemblyVersion>4.3.0</AssemblyVersion>
|
||||||
<FileVersion>4.2.0</FileVersion>
|
<FileVersion>4.3.0</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ namespace DigitalData.Core.Abstractions
|
|||||||
|
|
||||||
private bool IsBuilt => _lazyServiceProvider.IsValueCreated;
|
private bool IsBuilt => _lazyServiceProvider.IsValueCreated;
|
||||||
|
|
||||||
|
private PostBuildBehavior _pbBehavior = PostBuildBehavior.ThrowException;
|
||||||
|
|
||||||
|
public Factory BehaveOnPostBuild(PostBuildBehavior postBuildBehavior)
|
||||||
|
{
|
||||||
|
_pbBehavior = postBuildBehavior;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Factory()
|
public Factory()
|
||||||
{
|
{
|
||||||
_lazyServiceProvider = new Lazy<IServiceProvider>(() => _serviceCollection.BuildServiceProvider());
|
_lazyServiceProvider = new Lazy<IServiceProvider>(() => _serviceCollection.BuildServiceProvider());
|
||||||
@@ -30,6 +38,8 @@ namespace DigitalData.Core.Abstractions
|
|||||||
{
|
{
|
||||||
return _lazyServiceProvider.Value.GetService(serviceType);
|
return _lazyServiceProvider.Value.GetService(serviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IServiceScopeFactory ScopeFactory => this.GetRequiredService<IServiceScopeFactory>();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Service Collection
|
#region Service Collection
|
||||||
@@ -42,7 +52,8 @@ namespace DigitalData.Core.Abstractions
|
|||||||
get => _serviceCollection[index];
|
get => _serviceCollection[index];
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
EnsureNotBuilt();
|
if (EnsureBuilt())
|
||||||
|
return;
|
||||||
_serviceCollection[index] = value;
|
_serviceCollection[index] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,25 +65,29 @@ namespace DigitalData.Core.Abstractions
|
|||||||
|
|
||||||
public void Insert(int index, ServiceDescriptor item)
|
public void Insert(int index, ServiceDescriptor item)
|
||||||
{
|
{
|
||||||
EnsureNotBuilt();
|
if (EnsureBuilt())
|
||||||
|
return;
|
||||||
_serviceCollection.Insert(index, item);
|
_serviceCollection.Insert(index, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAt(int index)
|
public void RemoveAt(int index)
|
||||||
{
|
{
|
||||||
EnsureNotBuilt();
|
if (EnsureBuilt())
|
||||||
|
return;
|
||||||
_serviceCollection.RemoveAt(index);
|
_serviceCollection.RemoveAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(ServiceDescriptor item)
|
public void Add(ServiceDescriptor item)
|
||||||
{
|
{
|
||||||
EnsureNotBuilt();
|
if (EnsureBuilt())
|
||||||
|
return;
|
||||||
_serviceCollection.Add(item);
|
_serviceCollection.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
EnsureNotBuilt();
|
if (EnsureBuilt())
|
||||||
|
return;
|
||||||
_serviceCollection.Clear();
|
_serviceCollection.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +103,8 @@ namespace DigitalData.Core.Abstractions
|
|||||||
|
|
||||||
public bool Remove(ServiceDescriptor item)
|
public bool Remove(ServiceDescriptor item)
|
||||||
{
|
{
|
||||||
EnsureNotBuilt();
|
if (EnsureBuilt())
|
||||||
|
return false;
|
||||||
return _serviceCollection.Remove(item);
|
return _serviceCollection.Remove(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,11 +120,23 @@ namespace DigitalData.Core.Abstractions
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
private void EnsureNotBuilt()
|
private bool EnsureBuilt()
|
||||||
{
|
{
|
||||||
if (IsBuilt)
|
if (IsBuilt)
|
||||||
throw new InvalidOperationException("Service provider has already been built. No further service modifications are allowed.");
|
{
|
||||||
|
return _pbBehavior == PostBuildBehavior.ThrowException
|
||||||
|
? throw new InvalidOperationException("Service provider has already been built. No further service modifications are allowed.")
|
||||||
|
: true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum PostBuildBehavior
|
||||||
|
{
|
||||||
|
ThrowException,
|
||||||
|
Ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user