IA.Data/Ioc/IOCContainer.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using Ninject;
namespace IA.Data.Ioc
{
    public static class IOCContainer 
    {
        public static readonly IKernel mKernel= new StandardKernel();
       
        public static void Bind(Type pI, Type pT)
        {
            if (mKernel.GetBindings(pI).FirstOrDefault() == null)
                mKernel.Bind(pI).To(pT);
        }
     
        public static void Bind<I, T>() where T : I
        {
            lock (mKernel)
            {
                if (mKernel.GetBindings(typeof(I)).FirstOrDefault() == null)
                    mKernel.Bind<I>().To<T>();
            }
        }

        public static T Get<T>()
        {
            return mKernel.Get<T>();
        }

        public static T TryGet<T>()
        {
            return mKernel.TryGet<T>();
        }

        public static object TryGet(Type pI)
        {
            return mKernel.TryGet(pI);
        }

        public static IEnumerable<object> GetAll(Type pI)
        {
            return mKernel.GetAll(pI);
        }
        
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。