public List<FeatureInfo> GetBindingInformations(INinjectModule module)
        {
            List<FeatureInfo> bindingsFeatureInfoList = new List<FeatureInfo>();

            IKernel kernel = new StandardKernel();
            module.OnLoad(kernel);

            List<KeyValuePair<Type, ICollection<IBinding>>> typeBindingInfo = GetBindings(kernel, module.Name);

            foreach (KeyValuePair<Type, ICollection<IBinding>> typeBinding in typeBindingInfo)
            {
                FeatureInfo bindingInterface = new FeatureInfo(typeBinding.Key, null, null, FeatureType.BindingInterface);

                foreach (IBinding binding in typeBinding.Value)
                {
                    ContextMock contextMock = new ContextMock(kernel);

                    IProvider provider = binding.ProviderCallback(contextMock);

                    FeatureInfo bindingInterfaceImpl = new FeatureInfo(provider.Type, null, null, FeatureType.BindingImpl);
                    bindingInterfaceImpl.SetBindingType(binding.Target);

                    bindingInterface.AddDependency(bindingInterfaceImpl);
                }

                bindingsFeatureInfoList.Add(bindingInterface);
            }

            return bindingsFeatureInfoList;
        }
Пример #2
0
 public void AddDependency(FeatureInfo dependency)
 {
     this.dependenciesInfo.Add(dependency);
 }
        private FeatureInfo ProcessFeatureInstance(Type featureType)
        {
            var constructor = featureType.GetConstructors().OrderBy(c => c.GetParameters().Length).FirstOrDefault();

            Feature instance;
            if (constructor != null)
            {
                object[] arguments = new object[constructor.GetParameters().Length];

                instance = (Feature)Activator.CreateInstance(featureType, arguments);
            }
            else
            {
                instance = (Feature)Activator.CreateInstance(featureType);
            }

            Type factory = this.FindFactory(featureType);
            var dependencies = FindDependencies(featureType);

            var featureInfo = new FeatureInfo(featureType, factory, dependencies, FeatureType.Feature);
            GetNeededFeatures(instance, featureInfo);
            GetNeededExtensions(instance, featureInfo);
            GetModules(instance, featureInfo);

            return featureInfo;
        }
 private void GetModules(Feature ninjectFeature, FeatureInfo featureInfo)
 {
     List<INinjectModule> moduleList = ninjectFeature.Modules.ToList();
     foreach (INinjectModule module in moduleList)
     {
         FeatureInfo moduleInfo = new FeatureInfo(module.GetType(), null, null, FeatureType.Module);
         moduleInfo.AddDependency(this.bindingReader.GetBindingInformations(module));
         featureInfo.AddDependency(moduleInfo);
     }
 }
 private void GetNeededExtensions(Feature ninjectFeature, FeatureInfo featureInfo)
 {
     List<INinjectModule> neededExtensionList = ninjectFeature.NeededExtensions.ToList();
     foreach (INinjectModule neededExtension in neededExtensionList)
     {
         FeatureInfo needExtensionInfo = new FeatureInfo(neededExtension.GetType(), null, null, FeatureType.NeededExtensions);
         needExtensionInfo.AddDependency(this.bindingReader.GetBindingInformations(neededExtension));
         featureInfo.AddDependency(needExtensionInfo);
     }
 }
 private void GetNeededFeatures(Feature ninjectFeature, FeatureInfo featureInfo)
 {
     IList<Feature> neededFeatureList = ninjectFeature.NeededFeatures.ToList();
     foreach (Feature neededFeature in neededFeatureList)
     {
         FeatureInfo needfeatureInfo = ProcessFeatureInstance(neededFeature.GetType());
         needfeatureInfo.ChangeFeatureType(FeatureType.NeededFeature);
         featureInfo.AddDependency(needfeatureInfo);
     }
 }