<commit_before>﻿// Copyright (c) <NAME>. All rights reserved.
// This file is licensed under the BSD-Clause 2 license. 
// See the license.txt file in the project root for more information.

using System;
using System.IO;
using System.Reflection;
using Autofac;
using Lunet.Core;
using Microsoft.Extensions.Logging;

namespace Lunet
{
    public class SiteFactory
    {
        private readonly ContainerBuilder _containerBuilder;

        public SiteFactory()
        {
            _containerBuilder = new ContainerBuilder();

            // Pre-register some type
            _containerBuilder.RegisterInstance(this);
            _containerBuilder.RegisterType<LoggerFactory>().As<ILoggerFactory>().SingleInstance();
            _containerBuilder.RegisterType<SiteObject>().SingleInstance();
        }

        public ContainerBuilder ContainerBuilder => _containerBuilder;

        public SiteFactory Register<TPlugin>() where TPlugin : ISitePlugin
        {
            Register(typeof(TPlugin));
            return this;
        }

        public SiteFactory Register(Type pluginType)
        {
            if (pluginType == null) throw new ArgumentNullException(nameof(pluginType));
            if (!typeof(ISitePlugin).GetTypeInfo().IsAssignableFrom(pluginType))
            {
                throw new ArgumentException("Expecting a plugin type inheriting from ISitePlugin", nameof(pluginType));
            }
            _containerBuilder.RegisterType(pluginType).AsSelf().As<ISitePlugin>();
            return this;
        }

        public SiteObject Build()
        {
            var container = _containerBuilder.Build();
            return container.Resolve<SiteObject>();
        }
    }<commit_msg>Make sure that a plugin is only created once<commit_after>﻿// Copyright (c) <NAME>. All rights reserved.
// This file is licensed under the BSD-Clause 2 license. 
// See the license.txt file in the project root for more information.

using System;
using System.IO;
using System.Reflection;
using Autofac;
using Lunet.Core;
using Microsoft.Extensions.Logging;

namespace Lunet
{
    public class SiteFactory
    {
        private readonly ContainerBuilder _containerBuilder;

        public SiteFactory()
        {
            _containerBuilder = new ContainerBuilder();

            // Pre-register some type
            _containerBuilder.RegisterInstance(this);
            _containerBuilder.RegisterType<LoggerFactory>().As<ILoggerFactory>().SingleInstance();
            _containerBuilder.RegisterType<SiteObject>().SingleInstance();
        }

        public ContainerBuilder ContainerBuilder => _containerBuilder;

        public SiteFactory Register<TPlugin>() where TPlugin : ISitePlugin
        {
            Register(typeof(TPlugin));
            return this;
        }

        public SiteFactory Register(Type pluginType)
        {
            if (pluginType == null) throw new ArgumentNullException(nameof(pluginType));
            if (!typeof(ISitePlugin).GetTypeInfo().IsAssignableFrom(pluginType))
            {
                throw new ArgumentException("Expecting a plugin type inheriting from ISitePlugin", nameof(pluginType));
            }
            _containerBuilder.RegisterType(pluginType).SingleInstance().AsSelf().As<ISitePlugin>();
            return this;
        }

        public SiteObject Build()
        {
            var container = _containerBuilder.Build();
            return container.Resolve<SiteObject>();
        }
    }
{'fraction_non_alphanumeric': 0.08769407705577918, 'fraction_numerical': 0.0005750431282346176, 'mean_word_length': 2.535569105691057, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '2109287', 'n_tokens_mistral': 832, 'n_tokens_neox': 816, 'n_words': 218}