using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Abp.Dependency;
namespace Abp.Application.Features
{
///
/// Implements .
///
internal class FeatureManager : FeatureDefinitionContextBase, IFeatureManager, ISingletonDependency
{
private readonly IIocManager _iocManager;
private readonly IFeatureConfiguration _featureConfiguration;
///
/// Creates a new object
///
/// IOC Manager
/// Feature configuration
public FeatureManager(IIocManager iocManager, IFeatureConfiguration featureConfiguration)
{
_iocManager = iocManager;
_featureConfiguration = featureConfiguration;
}
///
/// Initializes this
///
public void Initialize()
{
foreach (var providerType in _featureConfiguration.Providers)
{
using (var provider = CreateProvider(providerType))
{
provider.Object.SetFeatures(this);
}
}
Features.AddAllFeatures();
}
///
/// Gets a feature by its given name
///
/// Name of the feature
public Feature Get(string name)
{
var feature = GetOrNull(name);
if (feature == null)
{
throw new AbpException("There is no feature with name: " + name);
}
return feature;
}
///
/// Gets all the features
///
public IReadOnlyList GetAll()
{
return Features.Values.ToImmutableList();
}
private IDisposableDependencyObjectWrapper CreateProvider(Type providerType)
{
return _iocManager.ResolveAsDisposable(providerType);
}
}
}