<commit_before>﻿using System;
using System.Collections.Generic;

using Autofac;

namespace ChessOk.ModelFramework
{
    /// <summary>
    /// Представляет собой <see cref="IModelContext"/> самого верхнего
    /// уровня. В пределах <see cref="ModelContext"/> регистрируются
    /// все классы, имеющие отношение к модели приложения.
    /// <seealso cref="RegistrationExtensions"/>
    /// </summary>
    public class ModelContext : IModelContext
    {
        private readonly ILifetimeScope _lifetimeScope;

        /// <summary>
        /// Инициализирует экземпляр класса <see cref="ModelContext"/>,
        /// используя <paramref name="parentScope"/>.
        /// </summary>
        /// <param name="parentScope">Autofac lifetime scope.</param>
        public ModelContext(ILifetimeScope parentScope)
        {
            _lifetimeScope = parentScope.BeginLifetimeScope(
                ContextHierarchy.ModelContext, 
                builder =>
                    {
                        builder.RegisterInstance(this).As<IModelContext>().AsSelf();
                        builder.Register(x => new ModelContextCache()).SingleInstance();
                    });
        }

        internal ModelContext(ILifetimeScope parentScope, object tag, Action<ContainerBuilder> configurationAction)
        {
            _lifetimeScope = parentScope.BeginLifetimeScope(tag, configurationAction);
        }

        public void Dispose()
        {
            _lifetimeScope.Dispose();
        }

        public T Get<T>()
        {
            return _lifetimeScope.Resolve<T>();
        }
        
        public object Get(Type serviceType)<commit_msg>ModelContext registers self instance as IModelContext<commit_after>﻿using System;
using System.Collections.Generic;

using Autofac;

namespace ChessOk.ModelFramework
{
    /// <summary>
    /// Представляет собой <see cref="IModelContext"/> самого верхнего
    /// уровня. В пределах <see cref="ModelContext"/> регистрируются
    /// все классы, имеющие отношение к модели приложения.
    /// <seealso cref="RegistrationExtensions"/>
    /// </summary>
    public class ModelContext : IModelContext
    {
        private readonly ILifetimeScope _lifetimeScope;

        /// <summary>
        /// Инициализирует экземпляр класса <see cref="ModelContext"/>,
        /// используя <paramref name="parentScope"/>.
        /// </summary>
        /// <param name="parentScope">Autofac lifetime scope.</param>
        public ModelContext(ILifetimeScope parentScope)
        {
            _lifetimeScope = parentScope.BeginLifetimeScope(
                ContextHierarchy.ModelContext, 
                builder =>
                    {
                        builder.RegisterInstance(this).As<IModelContext>().AsSelf();
                        builder.Register(x => new ModelContextCache()).SingleInstance();
                    });
        }

        internal ModelContext(ILifetimeScope parentScope, object tag, Action<ContainerBuilder> configurationAction)
        {
            _lifetimeScope = parentScope.BeginLifetimeScope(tag, builder =>
                {
                    builder.RegisterInstance(this).As<IModelContext>().AsSelf();
                    configurationAction(builder);
                });
        }

        public void Dispose()
        {
            _lifetimeScope.Dispose();
        }

        public T Get<T>()
        {
            return _lifetimeScope.Resolve<T>();
        }
        
        public object Get(Type serviceType)
{'fraction_non_alphanumeric': 0.10518814139110605, 'fraction_numerical': 0.0, 'mean_word_length': 2.009433962264151, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5384715', 'n_tokens_mistral': 912, 'n_tokens_neox': 926, 'n_words': 180}