<commit_before>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DefaultAppManager.cs" company="Kephas Software SRL">
//   Copyright (c) Kephas Software SRL. All rights reserved.
//   Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
// <summary>
//   Implements the default application manager class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Kephas.Application
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;

    using Kephas.Application.Composition;
    using Kephas.Composition;
    using Kephas.Diagnostics;
    using Kephas.Diagnostics.Contracts;
    using Kephas.Logging;
    using Kephas.Resources;
    using Kephas.Services;
    using Kephas.Services.Behaviors;
    using Kephas.Services.Composition;
    using Kephas.Sets;
    using Kephas.Threading.Tasks;

    /// <summary>
    /// The default application manager.
    /// </summary>
    [OverridePriority(Priority.Low)]
    public class DefaultAppManager : Loggable, IAppManager
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultAppManager"/> class.
        /// </summary>
        /// <param name="appManifest">The application manifest.</param>
        /// <param name="compositionContext">The ambient services.</param>
        /// <param name="serviceBehaviorProvider">The service behavior provider.</param>
        /// <param name="appLifecycleBehaviorFactories">The application lifecycle behavior factories.</param>
        /// <param name="featureManagerFactories">The feature manager factories.</param>
        /// <param name="featureLifecycleBehaviorFactories">The feature lifecycle behavior factories.</param>
        public DefaultAppManager(
            IAppManifest appManifest,
            ICompositionContext compositionContext,
            IServiceBehaviorProvider serviceBehaviorProvider,
            ICollection<IExportFactory<IAppLifecycleBehavior, AppServiceMetadata>> appLifecycleBehaviorFactories,
            ICollection<IExportFactory<IFeatureManager, FeatureManagerMetadata>> featureManagerFactories,
            ICollection<IExportFactory<IFeatureLifecycleBehavior, FeatureLifecycleBehaviorMetadata>> featureLifecycleBehaviorFactories)
        {
            Requires.NotNull(appManifest, nameof(appManifest));
            Requires.NotNull(compositionContext, nameof(compositionContext));
            Requires.NotNull(serviceBehaviorProvider, nameof(serviceBehaviorProvider));

            this.AppManifest = appManifest;
            this.CompositionContext = compositionContext;
            this.ServiceBehaviorProvider = serviceBehaviorProvider;
            this.AppLifecycleBehaviorFactories = appLifecycleBehaviorFactories == null
                                                     ? new List<IExportFactory<IAppLifecycleBehavior, AppServiceMetadata>>()
                                                     : this.ServiceBehaviorProvider.WhereEnabled(appLifecycleBehaviorFactories).ToList();

            this.EnsureMetadataHasFeatureInfo(featureManagerFactories);
            this.FeatureManagerFactories = featureManagerFactories == null
                                               ? new List<IExportFactory<IFeatureManager, FeatureManagerMetadata>>()
                                               : this.SortEnabledFeatureManagerFactories(
                                                   this.ServiceBehaviorProvider.WhereEnabled(featureManagerFactories).ToList());

            this.FeatureLifecycleBehaviorFactories = featureLifecycleBehaviorFactories == null
                                                         ? new List<IExportFactory<IFeatureLifecycleBehavior, FeatureLifecycleBehaviorMetadata>>()
                                                         : this.ServiceBehaviorProvider.WhereEnabled(featureLifecycleBehaviorFactories).ToList();
        }

        /// <summary>
        /// Gets the application manifest.
        /// </summary>
        public IAppManifest AppManifest { get; }

        /// <summary>
        /// Gets the composition context.
        /// </summary>
        /// <value>
        /// The composition context.
        /// </value>
        public ICompositionContext CompositionContext { get; }<commit_msg>Made DefaultAppManager simpler to instantiate.<commit_after>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DefaultAppManager.cs" company="Kephas Software SRL">
//   Copyright (c) Kephas Software SRL. All rights reserved.
//   Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
// <summary>
//   Implements the default application manager class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Kephas.Application
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;

    using Kephas.Application.Composition;
    using Kephas.Composition;
    using Kephas.Diagnostics;
    using Kephas.Diagnostics.Contracts;
    using Kephas.Logging;
    using Kephas.Resources;
    using Kephas.Services;
    using Kephas.Services.Behaviors;
    using Kephas.Services.Behaviors.Composition;
    using Kephas.Services.Composition;
    using Kephas.Sets;
    using Kephas.Threading.Tasks;

    /// <summary>
    /// The default application manager.
    /// </summary>
    [OverridePriority(Priority.Low)]
    public class DefaultAppManager : Loggable, IAppManager
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultAppManager"/> class.
        /// </summary>
        /// <param name="appManifest">The application manifest.</param>
        /// <param name="compositionContext">The ambient services.</param>
        /// <param name="serviceBehaviorProvider">Optional. The service behavior provider.</param>
        /// <param name="appLifecycleBehaviorFactories">Optional. The application lifecycle behavior factories.</param>
        /// <param name="featureManagerFactories">Optional. The feature manager factories.</param>
        /// <param name="featureLifecycleBehaviorFactories">Optional. The feature lifecycle behavior factories.</param>
        public DefaultAppManager(
            IAppManifest appManifest,
            ICompositionContext compositionContext,
            IServiceBehaviorProvider serviceBehaviorProvider = null,
            ICollection<IExportFactory<IAppLifecycleBehavior, AppServiceMetadata>> appLifecycleBehaviorFactories = null,
            ICollection<IExportFactory<IFeatureManager, FeatureManagerMetadata>> featureManagerFactories = null,
            ICollection<IExportFactory<IFeatureLifecycleBehavior, FeatureLifecycleBehaviorMetadata>> featureLifecycleBehaviorFactories = null)
        {
            Requires.NotNull(appManifest, nameof(appManifest));
            Requires.NotNull(compositionContext, nameof(compositionContext));

            this.AppManifest = appManifest;
            this.CompositionContext = compositionContext;
            this.ServiceBehaviorProvider = serviceBehaviorProvider ?? new DefaultServiceBehaviorProvider(compositionContext);
            this.AppLifecycleBehaviorFactories = appLifecycleBehaviorFactories == null
                                                     ? new List<IExportFactory<IAppLifecycleBehavior, AppServiceMetadata>>()
                                                     : this.ServiceBehaviorProvider.WhereEnabled(appLifecycleBehaviorFactories).ToList();

            this.EnsureMetadataHasFeatureInfo(featureManagerFactories);
            this.FeatureManagerFactories = featureManagerFactories == null
                                               ? new List<IExportFactory<IFeatureManager, FeatureManagerMetadata>>()
                                               : this.SortEnabledFeatureManagerFactories(this.ServiceBehaviorProvider.WhereEnabled(featureManagerFactories).ToList());

            this.FeatureLifecycleBehaviorFactories = featureLifecycleBehaviorFactories == null
                                                         ? new List<IExportFactory<IFeatureLifecycleBehavior, FeatureLifecycleBehaviorMetadata>>()
                                                         : this.ServiceBehaviorProvider.WhereEnabled(featureLifecycleBehaviorFactories).ToList();
        }

        /// <summary>
        /// Gets the application manifest.
        /// </summary>
        public IAppManifest AppManifest { get; }

        /// <summary>
        /// Gets the composition context.
        /// </summary>
        /// <value>
        /// The composition context.
        /// </value>
        public ICompositionContext CompositionContext { get; }
{'fraction_non_alphanumeric': 0.13357869668759473, 'fraction_numerical': 0.0, 'mean_word_length': 2.122338627914836, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5100546', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1983, 'n_words': 423}