Browse Source

Add Items to the ServiceConfigurationContext.

pull/400/head
Halil ibrahim Kalkan 8 years ago
parent
commit
6a8dbaf348
  1. 4
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/ModuleLoader.cs
  2. 21
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/ServiceConfigurationContext.cs

4
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/ModuleLoader.cs

@ -92,6 +92,8 @@ namespace Volo.Abp.Modularity
protected virtual void ConfigureServices(List<IAbpModuleDescriptor> modules, IServiceCollection services)
{
var context = new ServiceConfigurationContext(services);
services.AddSingleton(context);
//PreConfigureServices
foreach (var module in modules.Where(m => m.Instance is IPreConfigureServices))
{
@ -104,7 +106,7 @@ namespace Volo.Abp.Modularity
module.Instance.ConfigureServices(context);
}
//IPostConfigureServices
//PostConfigureServices
foreach (var module in modules.Where(m => m.Instance is IPostConfigureServices))
{
((IPostConfigureServices)module.Instance).PostConfigureServices(context);

21
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/ServiceConfigurationContext.cs

@ -1,4 +1,5 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
namespace Volo.Abp.Modularity
@ -7,9 +8,27 @@ namespace Volo.Abp.Modularity
{
public IServiceCollection Services { get; }
public IDictionary<string, object> Items { get; }
/// <summary>
/// Gets/sets arbitrary named objects those can be stored during
/// the service registration phase and shared between modules.
///
/// This is a shortcut usage of the <see cref="Items"/> dictionary.
/// Returns null if given key is not found in the <see cref="Items"/> dictionary.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object this[string key]
{
get => Items.GetOrDefault(key);
set => Items[key] = value;
}
public ServiceConfigurationContext([NotNull] IServiceCollection services)
{
Services = Check.NotNull(services, nameof(services));
Items = new Dictionary<string, object>();
}
}
}
Loading…
Cancel
Save