/// <summary> /// Shortcut to register the type as singleton for all implemented interfaces. /// </summary> /// <typeparam name="T">The type</typeparam> /// <param name="container">The injector</param> /// <returns>The container of registration options</returns> public static TypeRegistrationOptionsContainer RegisterSingletonWithInterfaces <T>(this IInjectorRegistry container) { var type = typeof(T); var interfaces = type.GetInterfaces(); var options = new List <TypeRegistrationOptions>(); foreach (var @interface in interfaces) { if (!container.IsRegistered(@interface) && @interface != typeof(IDisposable)) { var registrationOptions = container.RegisterType(@interface, type).AsSingleton(); options.Add(registrationOptions); } } var registrationsOptionsContainer = new TypeRegistrationOptionsContainer(options); return(registrationsOptionsContainer); }
/// <summary> /// Checks if the type is registered. /// </summary> /// <typeparam name="T">The type</typeparam> /// <param name="container">The injector</param> /// <returns>True if registered</returns> public static bool IsRegistered <T>(this IInjectorRegistry container) { return(container.IsRegistered(typeof(T))); }