/// <summary> /// Registers a type with it's implementation if it's not registered before. /// </summary> /// <param name="iocRegister">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> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot(this IIocRegister iocRegister, Type type, Type impl, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton) { if (iocRegister.IsRegistered(type)) { return(false); } iocRegister.Register(type, impl, lifeStyle); 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="iocRegister">Register</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 IIocRegister iocRegister, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton) where T : class { if (iocRegister.IsRegistered <T>()) { return(false); } iocRegister.Register <T>(lifeStyle); return(true); }