/src/Engine/MvcTurbine/ComponentModel/IServiceLocator.cs
https://github.com/tyronegroves/mvcturbine · C# · 126 lines · 23 code · 16 blank · 87 comment · 0 complexity · 0153899f648e021934436abee9ee21fe MD5 · raw file
- namespace MvcTurbine.ComponentModel {
- using System;
- using System.Collections.Generic;
-
- /// <summary>
- /// Provides a simple interface for resolving and registering components within
- /// the application.
- /// </summary>
- public interface IServiceLocator : IDisposable {
-
- /// <summary>
- /// Resolves the service of the specified type.
- /// </summary>
- /// <typeparam name="T">Type of service to resolve.</typeparam>
- /// <returns>An instance of the type, null otherwise.</returns>
- T Resolve<T>() where T : class;
-
- /// <summary>
- /// Resolves the service of the specified type by the given string key.
- /// </summary>
- /// <typeparam name="T">Type of service to resolve.</typeparam>
- /// <param name="key">Unique key to distinguish the service.</param>
- /// <returns>An instance of the type, null otherwise.</returns>
- T Resolve<T>(string key) where T : class;
-
- /// <summary>
- /// Resolves the service of the specified type by the given type key.
- /// </summary>
- /// <typeparam name="T">Type of service to resolve.</typeparam>
- /// <param name="type">Key type of the service.</param>
- /// <returns>An instance of the type, null otherwise.</returns>
- [Obsolete("Use object Resolve(Type type)")]
- T Resolve<T>(Type type) where T : class;
-
- ///<summary>
- /// Resolves the service of the specified type by the given type key.
- ///</summary>
- ///<param name="type">Type of service to resolve.</param>
- ///<returns>An instance of the type, null otherwise</returns>
- object Resolve(Type type);
-
- /// <summary>
- /// Resolves the list of services of type <see cref="T"/> that are registered
- /// within the locator.
- /// </summary>
- /// <typeparam name="T">Type of the service to resolve.</typeparam>
- /// <returns>A list of service of type <see cref="T"/>, null otherwise.</returns>
- IList<T> ResolveServices<T>() where T : class;
-
- IList<object> ResolveServices(Type type);
-
- /// <summary>
- /// Creates a <see cref="IServiceRegistrar"/> to process queued
- /// registration of types.
- /// </summary>
- /// <returns></returns>
- IServiceRegistrar Batch();
-
- /// <summary>
- /// Registers the implemation type, <paramref name="implType"/>, with the locator under
- /// the <see cref="Interface"/> service type.
- /// </summary>
- /// <typeparam name="Interface">Type of the service to register.</typeparam>
- /// <param name="implType">Implementation type to use for registration.</param>
- void Register<Interface>(Type implType) where Interface : class;
-
- /// <summary>
- /// Registers the implemation type, <see cref="Implementation"/>, with the locator under
- /// the <see cref="Interface"/> service type.
- /// </summary>
- /// <typeparam name="Interface">Type of the service to register.</typeparam>
- /// <typeparam name="Implementation">Implementation type to use for registration.
- /// </typeparam>
- void Register<Interface, Implementation>() where Implementation : class, Interface;
-
- /// <summary>
- /// Registers the implemation type, <see cref="Implementation"/>, with the locator under
- /// the <see cref="Interface"/> service type.
- /// </summary>
- /// <typeparam name="Interface">Type of the service to register.</typeparam>
- /// <typeparam name="Implementation">Implementation type to use for registration.
- /// </typeparam>
- /// <param name="key">Unique key to distinguish the service.</param>
- void Register<Interface, Implementation>(string key)
- where Implementation : class, Interface;
-
- /// <summary>
- /// Registers the implementation type, <paramref name="type"/>, with the locator
- /// by the given string key.
- /// </summary>
- /// <param name="key">Unique key to distinguish the service.</param>
- /// <param name="type">Implementation type to use.</param>
- void Register(string key, Type type);
-
- /// <summary>
- /// Registers the implementation type, <paramref name="implType"/>, with the locator
- /// by the given service type, <paramref name="serviceType"/>
- /// </summary>
- /// <param name="serviceType">Type of the service to register.</param>
- /// <param name="implType">Implementation to associate with the service.</param>
- void Register(Type serviceType, Type implType);
-
- /// <summary>
- /// Registers the implementation type, <paramref name="implType"/>, with the locator
- /// by the given service type, <paramref name="serviceType"/>
- /// </summary>
- /// <param name="serviceType">Type of the service to register.</param>
- /// <param name="implType">Implementation to associate with the service.</param>
- /// <param name="key">Unique key to distinguish the service.</param>
- void Register(Type serviceType, Type implType, string key);
-
- /// <summary>
- /// Registers the instance of type, <typeparamref name="Interface"/>, with the locator.
- /// </summary>
- /// <typeparam name="Interface">Type of the service to register.</typeparam>
- /// <param name="instance">Instance of the type to register.</param>
- void Register<Interface>(Interface instance) where Interface : class;
-
- /// <summary>
- /// Resolves the service of the specified interface with the provided factory method.
- /// </summary>
- /// <param name="factoryMethod">The factory method which will be used to resolve this interface.</param>
- /// <returns>An instance of the type, null otherwise</returns>
- void Register<Interface>(Func<Interface> factoryMethod) where Interface : class;
- }
- }