コード例 #1
0
ファイル: ConfigurationExtensions.cs プロジェクト: d18zj/qim
 private static void RegisterCommonComponents(IIocRegistrar registrar)
 {
     registrar.Register <IObjectSerializer, JsonNetSerializer>(LifetimeType.Singleton);
     registrar.Register <IAssemblyProvider, AssemblyProvider>(LifetimeType.Singleton);
     registrar.Register <ITypeFinder, AppTypeFinder>(LifetimeType.Singleton);
     registrar.RegisterType(typeof(ILogger <>), typeof(Logger <>));
 }
コード例 #2
0
        /// <summary>
        /// Registers a type with it's implementation if it's not registered before.
        /// </summary>
        /// <param name="iocRegistrar">Registrar</param>
        /// <param name="type">Type of the class</param>
        /// <param name="impl">The type that implements <paramref name="type"/></param>
        /// <param name="lifeStyle">Lifestyle of the objects of this type</param>
        public static void RegisterIfNot(this IIocRegistrar iocRegistrar, Type type, Type impl, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
        {
            if (iocRegistrar.IsRegistered(type))
            {
                return;
            }

            iocRegistrar.Register(type, impl, lifeStyle);
        }
コード例 #3
0
 /// <summary>
 /// Registers a type as self registration if it's not registered before.
 /// </summary>
 /// <param name="iocRegistrar">Registrar</param>
 /// <param name="type">Type of the class</param>
 /// <param name="lifeStyle">Lifestyle of the objects of this type</param>
 /// <returns>True, if registered for given implementation.</returns>
 public static bool RegisterIfNot(this IIocRegistrar iocRegistrar, Type type, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
 {
     if (iocRegistrar.IsRegistered(type))
     {
         return(false);
     }
     iocRegistrar.Register(type, lifeStyle);
     return(true);
 }
コード例 #4
0
 /// <summary>
 /// Registers a type as self registration if it's not registered before.
 /// </summary>
 /// <typeparam name="T">Type of the class</typeparam>
 /// <param name="iocRegistrar">Registrar</param>
 /// <param name="lifeStyle">Lifestyle of the objects of this type</param>
 /// <returns>True, if registered for given implementation.</returns>
 public static bool RegisterIfNot <T>(this IIocRegistrar iocRegistrar, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton) where T : class
 {
     if (iocRegistrar.IsRegistered <T>())
     {
         return(false);
     }
     iocRegistrar.Register <T>(lifeStyle);
     return(true);
 }
コード例 #5
0
        /// <summary>
        ///     没注册则去注册
        /// </summary>
        /// <typeparam name="TType"></typeparam>
        /// <typeparam name="TImpl"></typeparam>
        /// <param name="iocRegistrar"></param>
        /// <param name="lifeStyle"></param>
        /// <returns></returns>
        public static bool RegisterIfNot <TType, TImpl>(this IIocRegistrar iocRegistrar, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton) where TType : class where TImpl : class, TType
        {
            if (iocRegistrar.IsRegistered <TType>())
            {
                return(false);
            }

            iocRegistrar.Register <TType, TImpl>("", lifeStyle);
            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Registers the registrar with the IoC container.
        /// </summary>
        /// <param name="container">
        /// The IoC container with which the registrar will be registered.
        /// </param>
        /// <param name="registrar">
        /// The registrar to be registered.
        /// </param>
        /// <returns>The <paramref name="container"/>.</returns>
        public static IUnityContainer RegisterRegistrar(this IUnityContainer container, IIocRegistrar registrar)
        {
            if (registrar is null)
            {
                throw new ArgumentNullException(nameof(registrar));
            }

            registrar.Register(container);
            return(container);
        }
コード例 #7
0
        /// <summary>
        ///     Registers a type as self registration if it's not registered before.
        /// </summary>
        /// <typeparam name="T">Type of the class</typeparam>
        /// <param name="iocRegistrar">Registrar</param>
        /// <param name="lifeStyle">Lifestyle of the objects of this type</param>
        public static void RegisterIfAbsent <T>(this IIocRegistrar iocRegistrar, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
            where T : class
        {
            if (iocRegistrar.IsRegistered <T>())
            {
                return;
            }

            iocRegistrar.Register <T>(lifeStyle);
        }
コード例 #8
0
        /// <summary>
        ///     Registers a type with it's implementation if it's not registered before.
        /// </summary>
        /// <typeparam name="TType">Registering type</typeparam>
        /// <typeparam name="TImpl">The type that implements <see cref="TType" /></typeparam>
        /// <param name="iocRegistrar">Registrar</param>
        /// <param name="lifeStyle">Lifestyle of the objects of this type</param>
        public static void RegisterIfAbsent <TType, TImpl>(this IIocRegistrar iocRegistrar, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
            where TType : class
            where TImpl : class, TType
        {
            if (iocRegistrar.IsRegistered <TType>())
            {
                return;
            }

            iocRegistrar.Register <TType, TImpl>(lifeStyle);
        }
コード例 #9
0
 public void Should_Resolve_Self_Registered_Tests()
 {
     _registrar.Register <MyClass>();
     _resolver.Resolve <MyClass>();
 }