コード例 #1
0
        public virtual ContainerRegistration Register <TService>(TService instance)
        {
            if (Equals(instance, null))
            {
                throw new ArgumentNullException(nameof(instance), Messages.InstanceCannotBeNull);
            }

#if !NETSTANDARD1_6
            if (!typeof(TService).IsValueType && !typeof(TService).IsInterface)
            {
                throw new ArgumentException(Messages.TypeMustBeInterface, nameof(instance));
            }
#else
            if (!typeof(TService).GetTypeInfo().IsValueType&& !typeof(TService).GetTypeInfo().IsInterface)
            {
                throw new ArgumentException(Messages.TypeMustBeInterface, nameof(instance));
            }
#endif

            if (Logger.IsDebugEnabled)
            {
                Logger.Debug(Messages.RegisteringServiceInstance, typeof(TService));
            }
            var registration = new ContainerRegistration(instance);
            _registrations[typeof(TService)] = registration;
            return(registration);
        }
コード例 #2
0
ファイル: NanoContainer.cs プロジェクト: wadsworj/NEventStore
        public virtual ContainerRegistration Register <TService>(Func <NanoContainer, TService> resolve)
            where TService : class
        {
            Logger.Debug(Messages.RegisteringWireupCallback, typeof(TService));
            var registration = new ContainerRegistration(c => (object)resolve(c));

            _registrations[typeof(TService)] = registration;
            return(registration);
        }
コード例 #3
0
        public virtual ContainerRegistration Register <TService>(TService instance)
        {
            if (Equals(instance, null))
            {
                throw new ArgumentNullException(nameof(instance), Messages.InstanceCannotBeNull);
            }

            if (!typeof(TService).IsValueType && !typeof(TService).IsInterface)
            {
                throw new ArgumentException(Messages.TypeMustBeInterface, nameof(instance));
            }

            Logger.LogDebug(Messages.RegisteringServiceInstance, typeof(TService));
            var registration = new ContainerRegistration(instance);

            _registrations[typeof(TService)] = registration;
            return(registration);
        }