Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 internal Component(Container container, string name, ProviderFunc providerFunc)
 {
     resolvers = new ArrayList();
     this.container = container;
     this.name = name;
     ProviderFunc func = providerFunc;
     container.services[name] = func;
 }
Ejemplo n.º 3
0
 static DiContainer()
 {
     _instance = new Container();
 }
Ejemplo n.º 4
0
 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;
 }