<commit_before>﻿using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DD4T.ContentModel.Contracts.Configuration;
using DD4T.ContentModel.Contracts.Resolvers;
using DD4T.ContentModel.Contracts.Logging;
using DD4T.ContentModel.Contracts.Providers;
using DD4T.ContentModel.Factories;
using DD4T.Factories;
using DD4T.Utils;
using DD4T.Utils.Caching;
using DD4T.ContentModel.Contracts.Caching;

using DD4T.Utils.Resolver;
using DD4T.Utils.Logging;
using System.Reflection;
using System.IO;

namespace DD4T.DI.Ninject
{
    public static class Bootstrap
    {
        public static void UseDD4T(this IKernel kernel)
        {
            //not all dll's are loaded in the app domain. we will load the assembly in the appdomain to be able map the mapping
            var location = string.Format(@"{0}\bin\", AppDomain.CurrentDomain.BaseDirectory);
            var file = Directory.GetFiles(location, "DD4T.Providers.*").FirstOrDefault();
            var load = Assembly.LoadFile(file);

            var provider = AppDomain.CurrentDomain.GetAssemblies().Where(ass => ass.FullName.StartsWith("DD4T.Providers")).FirstOrDefault();
            var providerTypes = provider.GetTypes();
            var pageprovider = providerTypes.Where(a => typeof(IPageProvider).IsAssignableFrom(a)).FirstOrDefault();
            var cpProvider = providerTypes.Where(a => typeof(IComponentPresentationProvider).IsAssignableFrom(a)).FirstOrDefault();
            var linkProvider = providerTypes.Where(a => typeof(ILinkProvider).IsAssignableFrom(a)).FirstOrDefault();
            var facadeProvider = providerTypes.Where(a => typeof(IProvidersCommonServices).IsAssignableFrom(a)).FirstOrDefault();
            var binaryProvider = providerTypes.Where(a => typeof(IBinaryProvider).IsAssignableFrom(a)).FirstOrDefault();
            var componentProvider = providerTypes.Where(a => typeof(IComponentProvider).IsAssignableFrom(a)).FirstOrDefault();


            if (kernel.TryGet<IDD4TConfiguration>() == null)
                kernel.Bind<IDD4TConfiguration>().To<DD4TConfiguration>().InSingletonScope();

            if (kernel.TryGet<ILogger>() == null)
                kernel.Bind<ILogger>().To<NullLogger>().InSingletonScope();

            if (kernel.TryGet<IPublicationResolver>() == null)
                kernel.Bind<IPublicationResolver>().To<DefaultPublicationResolver>().InSingletonScope();

            if (kernel.TryGet<ICacheAgent>() == null)
                kernel.Bind<ICacheAgent>().To<DefaultCacheAgent>();

            //providers
            if (binaryProvider != null && kernel.TryGet<IBinaryProvider>() == null)
                kernel.Bind<IBinaryProvider>().To(binaryProvider);

            if (componentProvider != null && kernel.TryGet<IComponentProvider>() == null)
                kernel.Bind<IComponentProvider>().To(componentProvider);

            if (pageprovider != null && kernel.TryGet<IPageProvider>() == null)
                kernel.Bind<IPageProvider>().To(pageprovider);

            if (cpProvider != null && kernel.TryGet<IComponentPresentationProvider>() == null)
                kernel.Bind<IComponentPresentationProvider>().To(cpProvider);

            if (facadeProvider != null && kernel.TryGet<ILinkProvider>() == null)
                kernel.Bind<ILinkProvider>().To(linkProvider);

            if (binaryProvider != null && kernel.TryGet<IProvidersCommonServices>() == null)
                kernel.Bind<IProvidersCommonServices>().To(facadeProvider);

            //factories
            if (kernel.TryGet<IPageFactory>() == null)
                kernel.Bind<IPageFactory>().To<PageFactory>();

            if (kernel.TryGet<IComponentPresentationFactory>() == null)
                kernel.Bind<IComponentPresentationFactory>().To<ComponentPresentationFactory>();

            if (kernel.TryGet<ILinkFactory>() == null)
                kernel.Bind<ILinkFactory>().To<LinkFactory>();

            if (kernel.TryGet<IBinaryFactory>() == null)
                kernel.Bind<IBinaryFactory>().To<BinaryFactory>();

            if(kernel.TryGet<IComponentFactory>() ==  null)
                kernel.Bind<IComponentFactory>().To<ComponentFactory>();

            if (kernel.TryGet<IFactoryCommonServices>() == null)
                kernel.Bind<IFactoryCommonServices>().To<FactoryCommonServices>();

        }

    }
}<commit_msg>bugfix<commit_after>﻿using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DD4T.ContentModel.Contracts.Configuration;
using DD4T.ContentModel.Contracts.Resolvers;
using DD4T.ContentModel.Contracts.Logging;
using DD4T.ContentModel.Contracts.Providers;
using DD4T.ContentModel.Factories;
using DD4T.Factories;
using DD4T.Utils;
using DD4T.Utils.Caching;
using DD4T.ContentModel.Contracts.Caching;

using DD4T.Utils.Resolver;
using DD4T.Utils.Logging;
using System.Reflection;
using System.IO;

namespace DD4T.DI.Ninject
{
    public static class Bootstrap
    {
        public static void UseDD4T(this IKernel kernel)
        {
            //not all dll's are loaded in the app domain. we will load the assembly in the appdomain to be able map the mapping
            var location = string.Format(@"{0}\bin\", AppDomain.CurrentDomain.BaseDirectory);
            var file = Directory.GetFiles(location, "DD4T.Providers.*").FirstOrDefault();
            var load = Assembly.LoadFile(file);

            var provider = AppDomain.CurrentDomain.GetAssemblies().Where(ass => ass.FullName.StartsWith("DD4T.Providers")).FirstOrDefault();
            var providerTypes = provider.GetTypes();
            var pageprovider = providerTypes.Where(a => typeof(IPageProvider).IsAssignableFrom(a)).FirstOrDefault();
            var cpProvider = providerTypes.Where(a => typeof(IComponentPresentationProvider).IsAssignableFrom(a)).FirstOrDefault();
            var linkProvider = providerTypes.Where(a => typeof(ILinkProvider).IsAssignableFrom(a)).FirstOrDefault();
            var commonServices = providerTypes.Where(a => typeof(IProvidersCommonServices).IsAssignableFrom(a)).FirstOrDefault();
            var binaryProvider = providerTypes.Where(a => typeof(IBinaryProvider).IsAssignableFrom(a)).FirstOrDefault();
            var componentProvider = providerTypes.Where(a => typeof(IComponentProvider).IsAssignableFrom(a)).FirstOrDefault();


            if (kernel.TryGet<IDD4TConfiguration>() == null)
                kernel.Bind<IDD4TConfiguration>().To<DD4TConfiguration>().InSingletonScope();

            if (kernel.TryGet<ILogger>() == null)
                kernel.Bind<ILogger>().To<DefaultLogger>().InSingletonScope();

            if (kernel.TryGet<IPublicationResolver>() == null)
                kernel.Bind<IPublicationResolver>().To<DefaultPublicationResolver>().InSingletonScope();

            if (kernel.TryGet<ICacheAgent>() == null)
                kernel.Bind<ICacheAgent>().To<DefaultCacheAgent>();

            //providers
            if (binaryProvider != null && kernel.TryGet<IBinaryProvider>() == null)
                kernel.Bind<IBinaryProvider>().To(binaryProvider);

            if (componentProvider != null && kernel.TryGet<IComponentProvider>() == null)
                kernel.Bind<IComponentProvider>().To(componentProvider);

            if (pageprovider != null && kernel.TryGet<IPageProvider>() == null)
                kernel.Bind<IPageProvider>().To(pageprovider);

            if (cpProvider != null && kernel.TryGet<IComponentPresentationProvider>() == null)
                kernel.Bind<IComponentPresentationProvider>().To(cpProvider);

            if (linkProvider != null && kernel.TryGet<ILinkProvider>() == null)
                kernel.Bind<ILinkProvider>().To(linkProvider);

            if (commonServices != null && kernel.TryGet<IProvidersCommonServices>() == null)
                kernel.Bind<IProvidersCommonServices>().To(commonServices);

            //factories
            if (kernel.TryGet<IPageFactory>() == null)
                kernel.Bind<IPageFactory>().To<PageFactory>();

            if (kernel.TryGet<IComponentPresentationFactory>() == null)
                kernel.Bind<IComponentPresentationFactory>().To<ComponentPresentationFactory>();

            if (kernel.TryGet<ILinkFactory>() == null)
                kernel.Bind<ILinkFactory>().To<LinkFactory>();

            if (kernel.TryGet<IBinaryFactory>() == null)
                kernel.Bind<IBinaryFactory>().To<BinaryFactory>();

            if(kernel.TryGet<IComponentFactory>() ==  null)
                kernel.Bind<IComponentFactory>().To<ComponentFactory>();

            if (kernel.TryGet<IFactoryCommonServices>() == null)
                kernel.Bind<IFactoryCommonServices>().To<FactoryCommonServices>();

        }

    }
}
{'fraction_non_alphanumeric': 0.12779914046595792, 'fraction_numerical': 0.004297670210359647, 'mean_word_length': 3.221002386634845, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 101, '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': '6326789', 'n_tokens_mistral': 2441, 'n_tokens_neox': 2361, 'n_words': 384}