コード例 #1
0
        public void RegisterSingleton(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var instance = CreateInstance(type, null);
            var handle   = new ServiceHandle(type, instance);

            mServices.AddOrUpdate(handle, handle);
        }
コード例 #2
0
        public void Register(Type type, object instance)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            var handle = new ServiceHandle(type, instance);

            mServices.AddOrUpdate(handle, handle);
        }
コード例 #3
0
        public void Register(Type interfaceType, Type implementationType)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException(nameof(interfaceType));
            }

            if (implementationType == null)
            {
                throw new ArgumentNullException(nameof(implementationType));
            }

            var handle = new ServiceHandle(interfaceType, implementationType);

            mServices.AddOrUpdate(handle, handle);
        }
コード例 #4
0
        public void Register(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var info = type.GetTypeInfo();

            if (info.IsAbstract || info.IsInterface)
            {
                throw new ArgumentException($"The provided type \"{type.FullName}\" is an interface or abstract and can't be directly constructed.");
            }

            var handle = new ServiceHandle(type);

            mServices.AddOrUpdate(handle, handle);
        }
コード例 #5
0
 public bool Equals(ServiceHandle other)
 {
     return(mTypeHash.Equals(other.mTypeHash));
 }