using System; namespace Abp.Dependency { /// /// Extension methods for interface. /// public static class IocRegistrarExtensions { #region RegisterIfNot /// /// Registers a type as self registration if it's not registered before. /// /// Type of the class /// Registrar /// Lifestyle of the objects of this type /// True, if registered for given implementation. public static bool RegisterIfNot(this IIocRegistrar iocRegistrar, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton) where T : class { if (iocRegistrar.IsRegistered()) { return false; } iocRegistrar.Register(lifeStyle); return true; } /// /// Registers a type as self registration if it's not registered before. /// /// Registrar /// Type of the class /// Lifestyle of the objects of this type /// True, if registered for given implementation. 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; } /// /// Registers a type with it's implementation if it's not registered before. /// /// Registering type /// The type that implements /// Registrar /// Lifestyle of the objects of this type /// True, if registered for given implementation. public static bool RegisterIfNot(this IIocRegistrar iocRegistrar, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton) where TType : class where TImpl : class, TType { if (iocRegistrar.IsRegistered()) { return false; } iocRegistrar.Register(lifeStyle); return true; } /// /// Registers a type with it's implementation if it's not registered before. /// /// Registrar /// Type of the class /// The type that implements /// Lifestyle of the objects of this type /// True, if registered for given implementation. public static bool RegisterIfNot(this IIocRegistrar iocRegistrar, Type type, Type impl, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton) { if (iocRegistrar.IsRegistered(type)) { return false; } iocRegistrar.Register(type, impl, lifeStyle); return true; } #endregion } }