Ejemplo n.º 1
0
        private void CreateProvidersFromMethods(AbstractModule module)
        {
            foreach (MethodInfo methodInfo in module.GetType().GetMethodsWithAttribute <Provides>())
            {
                Provides provides        = (Provides)Attribute.GetCustomAttribute(methodInfo, typeof(Provides));
                Type[]   dependencyTypes = methodInfo.GetParameters().Select(param => param.ParameterType).ToArray();

                if (provides.Scope == Scope.NO_SCOPE)
                {
                    RegisterProvider(methodInfo.ReturnType, new MethodProvider(module, methodInfo, dependencyTypes));
                }
                else
                {
                    RegisterProvider(methodInfo.ReturnType,
                                     new SingletonMethodProvider(
                                         provides.Scope,
                                         module,
                                         methodInfo,
                                         dependencyTypes));
                }
            }
        }
Ejemplo n.º 2
0
 public MethodProvider(AbstractModule module, MethodInfo methodInfo, Type[] dependencyTypes)
     : base(methodInfo.ReturnType, dependencyTypes)
 {
     this.module     = module;
     this.methodInfo = methodInfo;
 }
 public SingletonMethodProvider(Scope scope, AbstractModule module, MethodInfo providerMethod, Type[] dependencyTypes)
     : base(scope, providerMethod.ReturnType, dependencyTypes)
 {
     this.module         = module;
     this.providerMethod = providerMethod;
 }
Ejemplo n.º 4
0
 public void RegisterModule(AbstractModule module)
 {
     module.Configure();
     RegisterBindings(module.Bindings);
     CreateProvidersFromMethods(module);
 }