<commit_before>﻿/*
 * This file is part of the CatLib package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Document: http://catlib.io/
 */

using System;

namespace CatLib
{
    ///<summary>
    /// 容器拓展
    /// </summary>
    public static class ContainerExpand
    {
        /// <summary>
        /// 以单例的形式绑定一个服务
        /// </summary>
        /// <param name="container">服务容器</param>
        /// <param name="service">服务名</param>
        /// <param name="concrete">服务实现</param>
        /// <returns>服务绑定数据</returns>
        public static IBindData Singleton(this IContainer container, string service, Func<IContainer, object[], object> concrete)
        {
            return container.Bind(service, concrete, true);
        }

        /// <summary>
        /// 以单例的形式绑定一个服务
        /// </summary>
        /// <typeparam name="TService">服务名</typeparam>
        /// <typeparam name="TConcrete">服务实现</typeparam>
        /// <param name="container">服务容器</param>
        /// <returns>服务绑定数据</returns>
        public static IBindData Singleton<TService, TConcrete>(this IContainer container) where TConcrete : class
        {
            return container.Bind(container.Type2Service(typeof(TService)), typeof(TConcrete), true);
        }

        /// <summary>
        /// 以单例的形式绑定一个服务
        /// </summary>
        /// <typeparam name="TService">服务名，同时也是服务实现</typeparam>
        /// <param name="container">服务容器</param>
        /// <returns>服务绑定数据</returns>
        public static IBindData Singleton<TService>(this IContainer container) where TService : class
        {
            return container.Bind(container.Type2Service(typeof(TService)), typeof(TService), true);
        }

        /// <summary>
        /// 以单例的形式绑定一个服务
        /// </summary>
        /// <typeparam name="TService">服务名</typeparam>
        /// <param name="container">服务容器</param>
        /// <param name="concrete">服务实现</param>
        /// <returns>服务绑定数据</returns>
        public static IBindData Singleton<TService>(this IContainer container, Func<IContainer, object[], object> concrete) where TService : class
        {
            return container.Bind(container.Type2Service(typeof(TService)), concrete, true);
        }

        /// <summary>
        /// 常规绑定一个服务
        /// </summary>
        /// <typeparam name="TService">服务名</typeparam>
        /// <typeparam name="TConcrete">服务实现</typeparam>
        /// <param name="container">服务容器</param>
        /// <returns>服务绑定数据</returns>
        public static IBindData Bind<TService, TConcrete>(this IContainer container) where TConcrete : class
        {
            return container.Bind(container.Type2Service(typeof(TService)), typeof(TConcrete), false);
        }

        /// <summary>
        /// 常规绑定一个服务
        /// </summary>
        /// <typeparam name="TService">服务名，同时也是服务实现</typeparam>
        /// <param name="container">服务容器</param>
        /// <returns>服务绑定数据</returns>
        public static IBindData Bind<TService>(this IContainer container) where TService : class
        {
            return container.Bind(container.Type2Service(typeof(TService)), typeof(TService), false);
        }

        /// <summary>
        /// 常规绑定一个服务
        /// </summary>
        /// <typeparam name="TService">服务名</typeparam>
        /// <param name="container">服务容器</param>
        /// <param name="concrete">服务实现</param>
        /// <returns>服务绑定数据</returns>
        public static IBindData Bind<TService>(this IContainer container, Func<IContainer, object[], object> concrete) where TService : class
        {
            return container.Bind(container.Type2Service(typeof(TService)), concrete, false);
        }

        /// <summary>
        /// 常规绑定一个服务
        /// </summary>
        /// <param name="container">服务容器</param>
        /// <param name="service">服务名</param>
        /// <param name="concrete">服务实现</param>
        /// <returns>服务绑定数据</returns>
        public static IBindData Bind(this IContainer container, string service, Func<IContainer, object[], object> concrete)
        {
            return container.Bind(service, concrete, false);
        }

        /// <summary>
        /// 构造一个服务，允许传入构造参数
        /// </summary>
        /// <typeparam name="TService">服务名</typeparam>
        /// <param name="container">服务容器</param>
        /// <param name="param">构造参数</param>
        /// <returns>服务实例</returns>
        public static TService MakeParams<TService>(this IContainer container, params object[] param)
        {
            return (TService)container.Make(container.Type2Service(typeof(TService)), param);
        }

        /// <summary>
        /// 构造一个服务
        /// </summary>
        /// <typeparam name="TService">服务名</typeparam>
        /// <param name="container">服务容器</param>
        /// <returns>服务实例</returns>
        public static TService Make<TService>(this IContainer container)
        {
            return (TService)container.Make(container.Type2Service(typeof(TService)));
        }

        /// <summary>
        /// 构造一个服务
        /// </summary>
        /// <typeparam name="TConvert">服务实例转换到的类型</typeparam>
        /// <param name="container">服务容器</param>
        /// <param name="service">服务名</param>
        /// <returns>服务实例</returns>
        public static TConvert Make<TConvert>(this IContainer container, string service)
        {
            return (TConvert)container.Make(service);
        }

        /// <summary>
        /// 释放服务
        /// </summary>
        /// <typeparam name="TService">服务名</typeparam>
        /// <param name="container">服务容器</param>
        public static void Release<TService>(this IContainer container) where TService : class
        {
            container.Release(container.Type2Service(typeof(TService)));
        }

        /// <summary>
        /// 静态化一个服务,实例值会经过解决修饰器
        /// </summary>
        /// <typeparam name="TService">服务名</typeparam>
        /// <param name="container">服务容器</param>
        /// <param name="instance">实例值</param>
        public static void Instance<TService>(this IContainer container, object instance) where TService : class
        {
            container.Instance(container.Type2Service(typeof(TService)), instance);
        }
    }
}<commit_msg>expand remove namespace<commit_after>﻿/*
 * This file is part of the CatLib package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Document: http://catlib.io/
 */

using System;
using CatLib;

///<summary>
/// 容器拓展
/// </summary>
public static class ContainerExpand
{
    /// <summary>
    /// 以单例的形式绑定一个服务
    /// </summary>
    /// <param name="container">服务容器</param>
    /// <param name="service">服务名</param>
    /// <param name="concrete">服务实现</param>
    /// <returns>服务绑定数据</returns>
    public static IBindData Singleton(this IContainer container, string service, Func<IContainer, object[], object> concrete)
    {
        return container.Bind(service, concrete, true);
    }

    /// <summary>
    /// 以单例的形式绑定一个服务
    /// </summary>
    /// <typeparam name="TService">服务名</typeparam>
    /// <typeparam name="TConcrete">服务实现</typeparam>
    /// <param name="container">服务容器</param>
    /// <returns>服务绑定数据</returns>
    public static IBindData Singleton<TService, TConcrete>(this IContainer container) where TConcrete : class
    {
        return container.Bind(container.Type2Service(typeof(TService)), typeof(TConcrete), true);
    }

    /// <summary>
    /// 以单例的形式绑定一个服务
    /// </summary>
    /// <typeparam name="TService">服务名，同时也是服务实现</typeparam>
    /// <param name="container">服务容器</param>
    /// <returns>服务绑定数据</returns>
    public static IBindData Singleton<TService>(this IContainer container) where TService : class
    {
        return container.Bind(container.Type2Service(typeof(TService)), typeof(TService), true);
    }

    /// <summary>
    /// 以单例的形式绑定一个服务
    /// </summary>
    /// <typeparam name="TService">服务名</typeparam>
    /// <param name="container">服务容器</param>
    /// <param name="concrete">服务实现</param>
    /// <returns>服务绑定数据</returns>
    public static IBindData Singleton<TService>(this IContainer container, Func<IContainer, object[], object> concrete) where TService : class
    {
        return container.Bind(container.Type2Service(typeof(TService)), concrete, true);
    }

    /// <summary>
    /// 常规绑定一个服务
    /// </summary>
    /// <typeparam name="TService">服务名</typeparam>
    /// <typeparam name="TConcrete">服务实现</typeparam>
    /// <param name="container">服务容器</param>
    /// <returns>服务绑定数据</returns>
    public static IBindData Bind<TService, TConcrete>(this IContainer container) where TConcrete : class
    {
        return container.Bind(container.Type2Service(typeof(TService)), typeof(TConcrete), false);
    }

    /// <summary>
    /// 常规绑定一个服务
    /// </summary>
    /// <typeparam name="TService">服务名，同时也是服务实现</typeparam>
    /// <param name="container">服务容器</param>
    /// <returns>服务绑定数据</returns>
    public static IBindData Bind<TService>(this IContainer container) where TService : class
    {
        return container.Bind(container.Type2Service(typeof(TService)), typeof(TService), false);
    }

    /// <summary>
    /// 常规绑定一个服务
    /// </summary>
    /// <typeparam name="TService">服务名</typeparam>
    /// <param name="container">服务容器</param>
    /// <param name="concrete">服务实现</param>
    /// <returns>服务绑定数据</returns>
    public static IBindData Bind<TService>(this IContainer container, Func<IContainer, object[], object> concrete) where TService : class
    {
        return container.Bind(container.Type2Service(typeof(TService)), concrete, false);
    }

    /// <summary>
    /// 常规绑定一个服务
    /// </summary>
    /// <param name="container">服务容器</param>
    /// <param name="service">服务名</param>
    /// <param name="concrete">服务实现</param>
    /// <returns>服务绑定数据</returns>
    public static IBindData Bind(this IContainer container, string service, Func<IContainer, object[], object> concrete)
    {
        return container.Bind(service, concrete, false);
    }

    /// <summary>
    /// 构造一个服务，允许传入构造参数
    /// </summary>
    /// <typeparam name="TService">服务名</typeparam>
    /// <param name="container">服务容器</param>
    /// <param name="param">构造参数</param>
    /// <returns>服务实例</returns>
    public static TService MakeParams<TService>(this IContainer container, params object[] param)
    {
        return (TService)container.Make(container.Type2Service(typeof(TService)), param);
    }

    /// <summary>
    /// 构造一个服务
    /// </summary>
    /// <typeparam name="TService">服务名</typeparam>
    /// <param name="container">服务容器</param>
    /// <returns>服务实例</returns>
    public static TService Make<TService>(this IContainer container)
    {
        return (TService)container.Make(container.Type2Service(typeof(TService)));
    }

    /// <summary>
    /// 构造一个服务
    /// </summary>
    /// <typeparam name="TConvert">服务实例转换到的类型</typeparam>
    /// <param name="container">服务容器</param>
    /// <param name="service">服务名</param>
    /// <returns>服务实例</returns>
    public static TConvert Make<TConvert>(this IContainer container, string service)
    {
        return (TConvert)container.Make(service);
    }

    /// <summary>
    /// 释放服务
    /// </summary>
    /// <typeparam name="TService">服务名</typeparam>
    /// <param name="container">服务容器</param>
    public static void Release<TService>(this IContainer container) where TService : class
    {
        container.Release(container.Type2Service(typeof(TService)));
    }

    /// <summary>
    /// 静态化一个服务,实例值会经过解决修饰器
    /// </summary>
    /// <typeparam name="TService">服务名</typeparam>
    /// <param name="container">服务容器</param>
    /// <param name="instance">实例值</param>
    public static void Instance<TService>(this IContainer container, object instance) where TService : class
    {
        container.Instance(container.Type2Service(typeof(TService)), instance);
    }
}
{'fraction_non_alphanumeric': 0.15953307392996108, 'fraction_numerical': 0.0016557662058117393, 'mean_word_length': 2.482271547996541, 'pattern_counts': {'":': 0, '<': 279, '<?xml version=': 0, '>': 279, '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': '6434980', 'n_tokens_mistral': 3812, 'n_tokens_neox': 3894, 'n_words': 676}