/// <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> /// Registers a type. /// </summary> /// <typeparam name="TFrom">the type from</typeparam> /// <typeparam name="TTo">The implementation type</typeparam> /// <param name="container">The injector</param> /// <returns>The registration options</returns> public static TypeRegistrationOptions RegisterType <TFrom, TTo>(this IInjectorRegistry container) where TTo : TFrom { return(container.RegisterType(typeof(TFrom), typeof(TTo))); }
/// <summary> /// Registers a type. /// </summary> /// <typeparam name="T">The type</typeparam> /// <param name="container">The injector</param> /// <param name="name">The name / key</param> /// <returns>The registration options</returns> public static TypeRegistrationOptions RegisterType <T>(this IInjectorRegistry container, string name) { return(container.RegisterType(typeof(T), name)); }
/// <summary> /// Registers a type as singleton. /// </summary> /// <typeparam name="TFrom">the type from</typeparam> /// <typeparam name="TTo">The implementation type</typeparam> /// <param name="container">The injector</param> /// <param name="name">The name / key</param> /// <returns>The registration options</returns> public static TypeRegistrationOptions RegisterSingleton <TFrom, TTo>(this IInjectorRegistry container, string name) where TTo : TFrom { return(container.RegisterType(typeof(TFrom), name, typeof(TTo)).AsSingleton()); }
/// <summary> /// Registers a type as singleton. /// </summary> /// <typeparam name="T">the type</typeparam> /// <param name="container">The injector</param> /// <returns>The registration options</returns> public static TypeRegistrationOptions RegisterSingleton <T>(this IInjectorRegistry container) { return(container.RegisterType(typeof(T)).AsSingleton()); }