Skip to content

Commit 7790dd8

Browse files
committed
# Conflicts: # src/SimpleInjector.Integration.ServiceCollection/SimpleInjectorAddOptions.cs
2 parents 92cadf7 + 3ef6931 commit 7790dd8

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

src/SimpleInjector.Integration.ServiceCollection/SimpleInjectorAddOptions.cs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,8 @@ internal SimpleInjectorAddOptions(
4545
/// <exception cref="ArgumentNullException">Thrown when a null value is provided.</exception>
4646
public IServiceProviderAccessor ServiceProviderAccessor
4747
{
48-
get
49-
{
50-
return this.serviceProviderAccessor;
51-
}
52-
53-
set
54-
{
55-
if (value is null)
56-
{
57-
throw new ArgumentNullException(nameof(value));
58-
}
59-
60-
this.serviceProviderAccessor = value;
61-
}
48+
get => this.serviceProviderAccessor;
49+
set => this.serviceProviderAccessor = value ?? throw new ArgumentNullException(nameof(value));
6250
}
6351

6452
/// <summary>
@@ -86,32 +74,32 @@ public IServiceProviderAccessor ServiceProviderAccessor
8674
/// The default is <c>true</c>. Set this value to <b>false</b> when running in an environment that does not
8775
/// support hosted services, e.g. Azure Functions.
8876
/// </summary>
89-
/// /// <value>A boolean value.</value>
77+
/// <value>A boolean value.</value>
9078
public bool EnableHostedServiceResolution { get; set; } = true;
9179

80+
/// <summary>
81+
/// Gets the framework's <see cref="IServiceScopeFactory"/> instance from the <see cref="ApplicationServices"/>.
82+
/// It's value will be set when
83+
/// <see cref="SimpleInjectorServiceCollectionExtensions.UseSimpleInjector(IServiceProvider, Container)">UseSimpleInjector</see>
84+
/// is called, or when ASP.NET Core resolves its hosted services (whatever comes first).
85+
/// </summary>
86+
/// <exception cref="InvalidOperationException">Thrown when the property has been called while ita value hasn't
87+
/// been set yet.</exception>
88+
/// <value>An IServiceScopeFactory.</value>
89+
public IServiceScopeFactory ServiceScopeFactory =>
90+
this.serviceScopeFactory ??= this.ApplicationServices.GetRequiredService<IServiceScopeFactory>();
91+
9292
/// <summary>
9393
/// Gets the <see cref="IServiceProvider"/> instance that will be used by Simple Injector to resolve
9494
/// cross-wired framework components. It's value will be set when
9595
/// <see cref="SimpleInjectorServiceCollectionExtensions.UseSimpleInjector(IServiceProvider, Container)">UseSimpleInjector</see>
9696
/// is called, or when ASP.NET Core resolves its hosted services (whatever comes first).
9797
/// </summary>
98+
/// <exception cref="InvalidOperationException">Thrown when the property has been called while ita value hasn't
99+
/// been set yet.</exception>
98100
/// <value>The <see cref="IServiceProvider"/> instance.</value>
99-
public IServiceProvider ApplicationServices
100-
{
101-
get
102-
{
103-
if (this.applicationServices is null)
104-
{
105-
throw this.GetServiceProviderNotSetException();
106-
}
107-
108-
return this.applicationServices;
109-
}
110-
}
111-
112-
internal IServiceScopeFactory ServiceScopeFactory =>
113-
this.serviceScopeFactory
114-
?? (this.serviceScopeFactory = this.GetRequiredFrameworkService<IServiceScopeFactory>());
101+
public IServiceProvider ApplicationServices =>
102+
this.applicationServices ?? throw this.GetServiceProviderNotSetException();
115103

116104
internal T GetRequiredFrameworkService<T>() => this.ApplicationServices.GetRequiredService<T>();
117105

0 commit comments

Comments
 (0)