public void Install(Container container) { container.Register(typeof(IVerdantEngine), typeof(VerdantEngine)).AsSingleton(); container.Register(typeof(PropertyDictionary), typeof(PropertyDictionary)).AsSingleton(); container.Register(typeof(ISpiChannelManager), typeof(SpiChannelManager)).AsSingleton(); }
internal Component(Container container, string name, ProviderFunc providerFunc) { resolvers = new ArrayList(); this.container = container; this.name = name; ProviderFunc func = providerFunc; container.services[name] = func; }
static DiContainer() { _instance = new Container(); }
internal Component(Container container, string name, Type type) { resolvers = new ArrayList(); this.container = container; this.name = name; ProviderFunc func = () => { var parameters = new ArrayList(); var parameterTypes = new ArrayList(); foreach (ProviderFunc resolver in resolvers) { var value = resolver(); parameters.Add(value); parameterTypes.Add(value.GetType()); } var constructor = type.GetConstructor((Type[])parameterTypes.ToArray(typeof(Type))); if (constructor == null) { throw new InvalidOperationException("Constructor matching the dependency chain for component '" + name + "' with type '" + type.FullName + "' could not be found."); } return constructor.Invoke(parameters.ToArray()); }; container.services[name] = func; }