/// <summary> /// Registers a type as self registration if it's not registered before. /// </summary> /// <param name="iocRegistror">Registrar</param> /// <param name="type">Type of the class</param> /// <param name="lifeTime">Life time of the objects of this type</param> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot(this IIocRegistrator iocRegistror, Type type, DependencyLifeTime lifeTime = DependencyLifeTime.Singleton) { if (iocRegistror.IsRegistered(type)) { return(false); } iocRegistror.Register(type, lifeTime); return(true); }
/// <summary> /// Registers a type as self registration if it's not registered before. /// </summary> /// <typeparam name="T">Type of the class</typeparam> /// <param name="iocRegistror">Registrar</param> /// <param name="lifeTime">Life time of the objects of this type</param> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot <T>(this IIocRegistrator iocRegistror, DependencyLifeTime lifeTime = DependencyLifeTime.Singleton) where T : class { if (iocRegistror.IsRegistered <T>()) { return(false); } iocRegistror.Register <T>(lifeTime); return(true); }
/// <summary> /// Registers a type with it's implementation if it's not registered before. /// </summary> /// <param name="iocRegistror">Registrar</param> /// <param name="serviceType">Type of the class</param> /// <param name="implementationType">The type that implements <paramref name="serviceType"/></param> /// <param name="lifeTime">Life time of the objects of this type</param> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot( this IIocRegistrator iocRegistror, Type serviceType, Type implementationType, DependencyLifeTime lifeTime = DependencyLifeTime.Singleton) { if (iocRegistror.IsRegistered(serviceType)) { return(false); } iocRegistror.Register(serviceType, implementationType, lifeTime); return(true); }
/// <summary> /// Registers a type with it's implementation if it's not registered before. /// </summary> /// <typeparam name="TService">Registering type</typeparam> /// <typeparam name="TImplementation">The type that implements <see cref="TType"/></typeparam> /// <param name="iocRegistror">Registrar</param> /// <param name="lifeTime">Life time of the objects of this type</param> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot <TService, TImplementation>( this IIocRegistrator iocRegistror, DependencyLifeTime lifeTime = DependencyLifeTime.Singleton) where TService : class where TImplementation : class, TService { if (iocRegistror.IsRegistered <TService>()) { return(false); } iocRegistror.Register <TService, TImplementation>(lifeTime); return(true); }