Beispiel #1
0
 /// <summary>
 /// Registers a custom service handler with the container.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <param name="container">The container.</param>
 /// <param name="handler">The handler.</param>
 /// <returns>The container.</returns>
 public static SimpleContainer Handler <TService>(this SimpleContainer container, Func <SimpleContainer, object> handler)
 {
     container.RegisterHandler(typeof(TService), null, handler);
     return(container);
 }
 public Func <T> Create(SimpleContainer container)
 {
     return(() => (T)container.GetInstance(typeof(T), null));
 }
Beispiel #3
0
 /// <summary>
 /// Registers an service to be created on each request.
 /// </summary>
 /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
 /// <param name="container">The container.</param>
 /// <returns>The container.</returns>
 public static SimpleContainer PerRequest <TImplementation>(this SimpleContainer container)
 {
     container.RegisterPerRequest(typeof(TImplementation), null, typeof(TImplementation));
     return(container);
 }
Beispiel #4
0
 /// <summary>
 /// Registers an instance with the container.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <param name="container">The container.</param>
 /// <param name="instance">The instance.</param>
 /// <returns>The container.</returns>
 public static SimpleContainer Instance <TService>(this SimpleContainer container, TService instance)
 {
     container.RegisterInstance(typeof(TService), null, instance);
     return(container);
 }
Beispiel #5
0
 /// <summary>
 /// Registers a singleton.
 /// </summary>
 /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
 /// <param name="container">The container.</param>
 /// <returns>The container.</returns>
 public static SimpleContainer Singleton <TImplementation>(this SimpleContainer container)
 {
     container.RegisterSingleton(typeof(TImplementation), null, typeof(TImplementation));
     return(container);
 }
Beispiel #6
0
 /// <summary>
 /// Registers an service to be created on each request.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
 /// <param name="container">The container.</param>
 /// <returns>The container.</returns>
 public static SimpleContainer PerRequest <TService, TImplementation>(this SimpleContainer container)
     where TImplementation : TService
 {
     container.RegisterPerRequest(typeof(TService), null, typeof(TImplementation));
     return(container);
 }
 /// <summary>
 /// Registers a singleton.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
 /// <param name="container">The container.</param>
 /// <param name="key">The key.</param>
 /// <returns>The container.</returns>
 public static SimpleContainer Singleton <TService, TImplementation>(this SimpleContainer container, string key = null)
     where TImplementation : TService
 {
     container.RegisterSingleton(typeof(TService), key, typeof(TImplementation));
     return(container);
 }
 /// <summary>
 /// Registers an service to be created on each request.
 /// </summary>
 /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
 /// <param name="container">The container.</param>
 /// <param name="key">The key.</param>
 /// <returns>The container.</returns>
 public static SimpleContainer PerRequest <TImplementation>(this SimpleContainer container, string key = null)
 {
     return(PerRequest <TImplementation, TImplementation>(container, key));
 }
 /// <summary>
 /// Registers a singleton.
 /// </summary>
 /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
 /// <param name="container">The container.</param>
 /// <param name="key">The key.</param>
 /// <returns>The container.</returns>
 public static SimpleContainer Singleton <TImplementation>(this SimpleContainer container, string key = null)
 {
     return(Singleton <TImplementation, TImplementation>(container, key));
 }
 /// <summary>
 /// Gets all instances of a particular type.
 /// </summary>
 /// <typeparam name="TService">The type to resolve.</typeparam>
 /// <param name="container">The container.</param>
 /// <returns>The resolved instances.</returns>
 public static IEnumerable <TService> GetAllInstances <TService>(this SimpleContainer container)
 {
     return(container.GetAllInstances(typeof(TService)).Cast <TService>());
 }
 /// <summary>
 /// Requests an instance.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <param name="container">The container.</param>
 /// <param name="key">The key.</param>
 /// <returns>The instance.</returns>
 public static TService GetInstance <TService>(this SimpleContainer container, string key = null)
 {
     return((TService)container.GetInstance(typeof(TService), key));
 }
 /// <summary>
 ///   Unregisters any handlers for the service/key that have previously been registered.
 /// </summary>
 /// <typeparam name="TService">The service type.</typeparam>
 /// <param name="container">The container.</param>
 /// <param name = "key">The key.</param>
 public static void UnregisterHandler <TService>(this SimpleContainer container, string key = null)
 {
     container.UnregisterHandler(typeof(TService), key);
 }
 /// <summary>
 /// Determines if a handler for the service/key has previously been registered.
 /// </summary>
 /// <typeparam name="TService">The service type.</typeparam>
 /// <param name="container">The container.</param>
 /// <param name="key">The key.</param>
 /// <returns>True if a handler is registere; false otherwise.</returns>
 public static bool HasHandler <TService>(this SimpleContainer container, string key = null)
 {
     return(container.HasHandler(typeof(TService), key));
 }