本文整理汇总了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();
}
}
}
示例2: TwoPhasedPipelineAdaptor
public TwoPhasedPipelineAdaptor(IDependencyResolver resolver)
{
_graphs = resolver.HasDependency<IGenerateCallGraphs>()
? resolver.Resolve<IGenerateCallGraphs>()
: new WeightedCallGraphGenerator();
Contributors = resolver.ResolveAll<IPipelineContributor>()
.ToList()
.AsReadOnly();
}
示例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);
}
示例4: DefaultHubManager
public DefaultHubManager(IDependencyResolver resolver)
{
_hubProviders = resolver.ResolveAll<IHubDescriptorProvider>();
_methodProviders = resolver.ResolveAll<IMethodDescriptorProvider>();
_activator = resolver.Resolve<IHubActivator>();
}
示例5: MetaModelRepository
// TODO: Remove when impelemntation of array injection in containers is complete
public MetaModelRepository(IDependencyResolver resolver) : this(resolver.ResolveAll<IMetaModelHandler>().ToArray())
{
}
示例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)
{
}
示例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);
}
}
示例8: SystemAndAttributesOperationInterceptorProvider
public SystemAndAttributesOperationInterceptorProvider(IDependencyResolver resolver)
: this(resolver.ResolveAll<IOperationInterceptor>().ToArray())
{
}
示例9: DefaultHubManager
public DefaultHubManager(IDependencyResolver resolver) : this(
resolver.ResolveAll<IHubDescriptorProvider>(),
resolver.ResolveAll<IMethodDescriptorProvider>(),
resolver.Resolve<IHubActivator>())
{
}