Browse Source

Check multiple configure services calls and rename ManualConfigureServices to SkipConfigureServices.

pull/10928/head
Halil İbrahim Kalkan 4 years ago
parent
commit
d9a5b86505
  1. 20
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs
  2. 3
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationCreationOptions.cs
  3. 8
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationFactory.cs
  4. 7
      framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs
  5. 7
      framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplicationWithExternalServiceProvider.cs
  6. 5
      framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplicationWithInternalServiceProvider.cs

20
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs

@ -24,6 +24,8 @@ public abstract class AbpApplicationBase : IAbpApplication
public IReadOnlyList<IAbpModuleDescriptor> Modules { get; }
private bool _configuredServices;
internal AbpApplicationBase(
[NotNull] Type startupModuleType,
[NotNull] IServiceCollection services,
@ -48,7 +50,7 @@ public abstract class AbpApplicationBase : IAbpApplication
Modules = LoadModules(services, options);
if (!options.ManualConfigureServices)
if (!options.SkipConfigureServices)
{
ConfigureServices();
}
@ -139,6 +141,8 @@ public abstract class AbpApplicationBase : IAbpApplication
//TODO: We can extract a new class for this
public virtual async Task ConfigureServicesAsync()
{
CheckMultipleConfigureServices();
var context = new ServiceConfigurationContext(Services);
Services.AddSingleton(context);
@ -211,11 +215,23 @@ public abstract class AbpApplicationBase : IAbpApplication
abpModule.ServiceConfigurationContext = null;
}
}
_configuredServices = true;
}
private void CheckMultipleConfigureServices()
{
if (_configuredServices)
{
throw new AbpInitializationException("Services have already been configured! If you call ConfigureServicesAsync method, you must have set AbpApplicationCreationOptions.SkipConfigureServices tu true before.");
}
}
//TODO: We can extract a new class for this
public virtual void ConfigureServices()
{
CheckMultipleConfigureServices();
var context = new ServiceConfigurationContext(Services);
Services.AddSingleton(context);
@ -288,5 +304,7 @@ public abstract class AbpApplicationBase : IAbpApplication
abpModule.ServiceConfigurationContext = null;
}
}
_configuredServices = true;
}
}

3
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationCreationOptions.cs

@ -19,13 +19,12 @@ public class AbpApplicationCreationOptions
[NotNull]
public AbpConfigurationBuilderOptions Configuration { get; }
public bool ManualConfigureServices { get; set; }
public bool SkipConfigureServices { get; set; }
public AbpApplicationCreationOptions([NotNull] IServiceCollection services)
{
Services = Check.NotNull(services, nameof(services));
PlugInSources = new PlugInSourceList();
Configuration = new AbpConfigurationBuilderOptions();
ManualConfigureServices = false;
}
}

8
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationFactory.cs

@ -15,7 +15,7 @@ public static class AbpApplicationFactory
var app = Create(typeof(TStartupModule), options =>
{
optionsAction?.Invoke(options);
options.ManualConfigureServices = true;
options.SkipConfigureServices = true;
});
await app.ConfigureServicesAsync();
return app;
@ -28,7 +28,7 @@ public static class AbpApplicationFactory
var app = new AbpApplicationWithInternalServiceProvider(startupModuleType, options =>
{
optionsAction?.Invoke(options);
options.ManualConfigureServices = true;
options.SkipConfigureServices = true;
});
await app.ConfigureServicesAsync();
return app;
@ -42,7 +42,7 @@ public static class AbpApplicationFactory
var app = Create(typeof(TStartupModule), services, options =>
{
optionsAction?.Invoke(options);
options.ManualConfigureServices = true;
options.SkipConfigureServices = true;
});
await app.ConfigureServicesAsync();
return app;
@ -56,7 +56,7 @@ public static class AbpApplicationFactory
var app = new AbpApplicationWithExternalServiceProvider(startupModuleType, services, options =>
{
optionsAction?.Invoke(options);
options.ManualConfigureServices = true;
options.SkipConfigureServices = true;
});
await app.ConfigureServicesAsync();
return app;

7
framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs

@ -23,6 +23,13 @@ public interface IAbpApplication : IModuleContainer, IDisposable
/// This can not be used before initialize the application.
/// </summary>
IServiceProvider ServiceProvider { get; }
/// <summary>
/// Calls the Pre/Post/ConfigureServicesAsync methods of the modules.
/// If you use this method, you must have set the <see cref="AbpApplicationCreationOptions.SkipConfigureServices"/>
/// option to true before.
/// </summary>
Task ConfigureServicesAsync();
/// <summary>
/// Used to gracefully shutdown the application and all modules.

7
framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplicationWithExternalServiceProvider.cs

@ -10,12 +10,7 @@ public interface IAbpApplicationWithExternalServiceProvider : IAbpApplication
/// Sets the service provider, but not initializes the modules.
/// </summary>
void SetServiceProvider([NotNull] IServiceProvider serviceProvider);
/// <summary>
/// Call the Pre/Post/ConfigureServicesAsync method of the modules.
/// </summary>
Task ConfigureServicesAsync();
/// <summary>
/// Sets the service provider and initializes all the modules.
/// If <see cref="SetServiceProvider"/> was called before, the same

5
framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplicationWithInternalServiceProvider.cs

@ -11,11 +11,6 @@ public interface IAbpApplicationWithInternalServiceProvider : IAbpApplication
/// </summary>
IServiceProvider CreateServiceProvider();
/// <summary>
/// Call the Pre/Post/ConfigureServicesAsync method of the modules.
/// </summary>
Task ConfigureServicesAsync();
/// <summary>
/// Creates the service provider and initializes all the modules.
/// If <see cref="CreateServiceProvider"/> method was called before,

Loading…
Cancel
Save