当前位置: 首页>>代码示例>>C#>>正文


C# IDependencyResolver.ResolveAll方法代码示例

本文整理汇总了C#中IDependencyResolver.ResolveAll方法的典型用法代码示例。如果您正苦于以下问题:C# IDependencyResolver.ResolveAll方法的具体用法?C# IDependencyResolver.ResolveAll怎么用?C# IDependencyResolver.ResolveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDependencyResolver的用法示例。


在下文中一共展示了IDependencyResolver.ResolveAll方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunContainerInitializers

        private static void RunContainerInitializers(IDependencyResolver dependencyResolver)
        {
            var appdomainHelpers = dependencyResolver.ResolveAll<IAppDomainHelper>();
            if (appdomainHelpers == null || appdomainHelpers.Count() == 0)
            {
                appdomainHelpers = new[] {AppDomainHelper.CreateDefault()};
            }

            var initTasks =
                appdomainHelpers.SelectMany(helper => helper.GetTypes(
                    t => t.IsClass && !t.IsAbstract && typeof (IContainerInitializer).IsAssignableFrom(t)));
            //register them:
            foreach (var taskType in initTasks)
            {
                dependencyResolver.RegisterType(typeof(IContainerInitializer), taskType);
            }
            //run them:
            var allTasks = dependencyResolver.ResolveAll<IContainerInitializer>();
            if (allTasks != null)
            {
                //first user's tasks:
                foreach (var task in allTasks.Where(t => !t.GetType().Namespace.StartsWith("BoC.")))
                {
                    task.Execute();
                }
                //now ours:
                foreach (var task in allTasks.Where(t => t.GetType().Namespace.StartsWith("BoC.")))
                {
                    task.Execute();
                }
            }
        }
开发者ID:JoeyCyril,项目名称:BoC,代码行数:32,代码来源:IoC.cs

示例2: TwoPhasedPipelineAdaptor

 public TwoPhasedPipelineAdaptor(IDependencyResolver resolver)
 {
   _graphs = resolver.HasDependency<IGenerateCallGraphs>()
       ? resolver.Resolve<IGenerateCallGraphs>()
       : new WeightedCallGraphGenerator();
   Contributors = resolver.ResolveAll<IPipelineContributor>()
                          .ToList()
                          .AsReadOnly();
 }
开发者ID:openrasta,项目名称:openrasta-core,代码行数:9,代码来源:TwoPhasedPipelineAdaptor.cs

示例3: InitializeSessionFactory

        public static ISessionFactory InitializeSessionFactory(IDependencyResolver dependencyResolver)
        {
            String databaseName = null;
            foreach (ConnectionStringSettings connectionString in ConfigurationManager.ConnectionStrings)
            {
                if (!String.IsNullOrEmpty(connectionString.Name) &&
                    connectionString.Name.EndsWith("db4o", StringComparison.InvariantCultureIgnoreCase))
                {
                    databaseName = connectionString.ConnectionString;
                }
            }

            if (databaseName == null)
            {
                throw new Exception("Could not find a connectionstring that ends with 'db4o'.");
            }

            databaseName = databaseName.Replace(
                "|DataDirectory|",
                AppDomain.CurrentDomain.GetData("DataDirectory") + "\\");

            IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
            config.Common.Add(new TransparentActivationSupport());
            config.Common.Add(new TransparentPersistenceSupport());
            config.Common.DetectSchemaChanges = true;
            config.Common.ExceptionsOnNotStorable = true;
            config.Common.OptimizeNativeQueries = true;
            config.Common.UpdateDepth = Int32.MaxValue;

            dependencyResolver.RegisterInstance<IEmbeddedConfiguration>(config);

            var configExtenders = dependencyResolver.ResolveAll<IConfigurationExtender>() ?? new IConfigurationExtender[0];
            foreach (var extender in configExtenders)
            {
                extender.Configure(config);
            }

            var db = Db4oEmbedded.OpenFile(config, databaseName);
            AutoIncrementSupport.Install(db);
            return new Db4oSessionFactory(db);
        }
开发者ID:JoeyCyril,项目名称:BoC,代码行数:41,代码来源:Db4oSessionFactory.cs

示例4: DefaultHubManager

 public DefaultHubManager(IDependencyResolver resolver)
 {
     _hubProviders = resolver.ResolveAll<IHubDescriptorProvider>();
     _methodProviders = resolver.ResolveAll<IMethodDescriptorProvider>();
     _activator = resolver.Resolve<IHubActivator>();
 }
开发者ID:Djohnnie,项目名称:Sonarr,代码行数:6,代码来源:DefaultHubManager.cs

示例5: MetaModelRepository

 // TODO: Remove when impelemntation of array injection in containers is complete
 public MetaModelRepository(IDependencyResolver resolver) : this(resolver.ResolveAll<IMetaModelHandler>().ToArray())
 {
 }
开发者ID:endjin,项目名称:openrasta-stable,代码行数:4,代码来源:MetaModelRepository.cs

示例6: MethodBasedOperationCreator

 //// TODO: Remove when support for arrays is added to containers
 public MethodBasedOperationCreator(IDependencyResolver resolver, IObjectBinderLocator binderLocator)
     : this(resolver.ResolveAll<IMethodFilter>().ToArray(), resolver, binderLocator)
 {
 }
开发者ID:dhootha,项目名称:openrasta-core,代码行数:5,代码来源:MethodBasedOperationCreator.cs

示例7: GenerateRepositories

        public static void GenerateRepositories(IDependencyResolver dependencyResolver, Type defaultBaseType, Type[] constructorParams)
        {
            const string idPropertyName = "Id";
            var interfaceToFind = typeof(IRepository<>);

            var isbasetype = new Func<Type, bool>(basetype =>
                                                  basetype.IsGenericType &&
                                                  basetype.GetGenericTypeDefinition() == typeof (BaseEntity<>));

            //below should work fine for all situations :)
            ModuleBuilder mb = null;
            var types = dependencyResolver.ResolveAll<IAppDomainHelper>().SelectMany(
                helper => helper.GetTypes(t => true)).ToArray();

            var entities = from t in types
                           where t.IsClass
                                 && !t.IsAbstract
                                 && typeof (IBaseEntity).IsAssignableFrom(t)
                                 && !isbasetype(t)
                           select t;

            int typeNum = 0;
            foreach (var type in entities.ToArray())
            {
                var idProp = type.GetProperty(idPropertyName);
                var idType = idProp == null ? typeof(object) : idProp.PropertyType;
                var interfaceType = interfaceToFind.MakeGenericType(new Type[] { type });

                if (interfaceType == null)
                {
                    continue;
                }

                var toFind = (from i in types
                              where i.IsInterface &&
                                    interfaceType.IsAssignableFrom(i)
                              select i).FirstOrDefault() ?? interfaceType;

                if (dependencyResolver.IsRegistered(toFind))
                {
                    //this repository is already registered, if you have multiple repositories implementing the same interface,
                    //you'll have to register the correct one 'by hand'
                    continue;
                }

                var repo = (from r in types
                            where !r.IsInterface &&
                                  toFind.IsAssignableFrom(r)
                            select r
                           ).FirstOrDefault();

                if (repo == null)
                {
                    if (mb == null)
                        mb = GetRepositoriesModuleBuilder();
                    var name = "DynamicGeneratedRepository" + typeNum++;

                    var baseType = defaultBaseType.MakeGenericType(new Type[] { type });
                    var baseConstructor = baseType.GetConstructor(constructorParams);
                    var tb = mb.DefineType(name, TypeAttributes.AutoLayout | TypeAttributes.Public,
                                           baseType,
                                           new Type[] {toFind});
                    var constructor = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard,
                                                           constructorParams);
                    for (int i = 1; i <= constructorParams.Length; i++)
                    {
                        constructor.DefineParameter(i, ParameterAttributes.None, "param" + i);
                    }

                    ILGenerator ilGenerator = constructor.GetILGenerator();
                    ilGenerator.Emit(OpCodes.Ldarg_0);                      // Load "this"
                    for (int i = 1; i <= constructorParams.Length; i++)
                    {
                        ilGenerator.Emit(OpCodes.Ldarg, i);
                    }
                    ilGenerator.Emit(OpCodes.Call, baseConstructor);    // Call the base constructor
                    ilGenerator.Emit(OpCodes.Ret);
                    try
                    {
                        repo = tb.CreateType();
                    }
                    catch (TypeLoadException exception)
                    {
                        throw new TypeLoadException("Error creating an automatic generated Repository for " + toFind, exception);
                    }
                }
                dependencyResolver.RegisterType(interfaceType, repo);
                dependencyResolver.RegisterType(toFind, repo);
            }
        }
开发者ID:JoeyCyril,项目名称:BoC,代码行数:90,代码来源:RepositoryGenerator.cs

示例8: SystemAndAttributesOperationInterceptorProvider

 public SystemAndAttributesOperationInterceptorProvider(IDependencyResolver resolver)
     : this(resolver.ResolveAll<IOperationInterceptor>().ToArray())
 {
 }
开发者ID:endjin,项目名称:openrasta-stable,代码行数:4,代码来源:SystemAndAttributesOperationInterceptorProvider.cs

示例9: DefaultHubManager

		public DefaultHubManager(IDependencyResolver resolver) : this(
			resolver.ResolveAll<IHubDescriptorProvider>(), 
			resolver.ResolveAll<IMethodDescriptorProvider>(), 
			resolver.Resolve<IHubActivator>())
        {
        }
开发者ID:SaveTrees,项目名称:SignalR,代码行数:6,代码来源:DefaultHubManager.cs


注:本文中的IDependencyResolver.ResolveAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。