namespace Caliburn.Micro.Core { using System; using System.Linq; using System.Collections.Generic; /// /// Used by the framework to pull instances from an IoC container and to inject dependencies into certain existing classes. /// public static class IoC { /// /// Gets an instance by type and key. /// public static Func GetInstance = (service, key) => { throw new InvalidOperationException("IoC is not initialized."); }; /// /// Gets all instances of a particular type. /// public static Func> GetAllInstances = service => { throw new InvalidOperationException("IoC is not initialized."); }; /// /// Passes an existing instance to the IoC container to enable dependencies to be injected. /// public static Action BuildUp = instance => { throw new InvalidOperationException("IoC is not initialized."); }; /// /// Gets an instance from the container. /// /// The type to resolve. /// The key to look up. /// The resolved instance. public static T Get(string key = null) { return (T)GetInstance(typeof(T), key); } /// /// Gets all instances of a particular type. /// /// The type to resolve. /// The resolved instances. public static IEnumerable GetAll() { return GetAllInstances(typeof(T)).Cast(); } } }