本文整理汇总了C#中IContainer.GetAllInstances方法的典型用法代码示例。如果您正苦于以下问题:C# IContainer.GetAllInstances方法的具体用法?C# IContainer.GetAllInstances怎么用?C# IContainer.GetAllInstances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContainer
的用法示例。
在下文中一共展示了IContainer.GetAllInstances方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeStartupRunners
private static void InitializeStartupRunners(IContainer existingContainer)
{
var mappingDefinitions = existingContainer.GetAllInstances<IRunAtStartup>().ToList();
mappingDefinitions.ForEach(mappingDefinition => mappingDefinition.Init());
Mapper.AssertConfigurationIsValid();
}
示例2: Execute
public void Execute(IContainer container)
{
log4net.Config.XmlConfigurator.Configure();
container.Configure(x =>
{
x.Scan(scanner =>
{
scanner.AssembliesFromApplicationBaseDirectory(assembly => assembly.GetName().Name.StartsWith("Example"));
scanner.AddAllTypesOf(typeof (IStartup));
scanner.AddAllTypesOf(typeof(IConsumer));
scanner.SingleImplementationsOfInterface();
scanner.WithDefaultConventions();
});
x.For<ILog>().Use(LogManager.GetLogger(typeof(StartupTask)));
});
foreach (var task in container.GetAllInstances<IStartup>())
{
task.Execute(container);
}
// must be done out of the normal configuration due to the dependence on the
// scan for consumers having been completed.
container.Inject(typeof(IServiceBus),
ServiceBusFactory.New(sbc =>
{
sbc.UseRabbitMq();
sbc.UseControlBus();
sbc.ReceiveFrom(ConfigurationManager.AppSettings["WebDenormalizerMessageQueue"]);
sbc.Subscribe(subs => subs.LoadFrom(container));
}));
}
示例3: ExecuteEndTasks
public void ExecuteEndTasks(IContainer nestedContainer)
{
foreach (var task in nestedContainer.GetAllInstances<IRunAfterEachRequest>())
{
task.Execute();
}
}
示例4: GetArgumentValue
private object GetArgumentValue(
ParameterInfo parameter,
ArgumentCollection constructorArguments,
IContainer container)
{
object value;
if (constructorArguments.Contains(parameter.Name))
{
value = constructorArguments[parameter.Name];
}
else if (parameter.ParameterType.IsArray)
{
var elementType = parameter.ParameterType.GetElementType();
var arrayCastDelegate = ArrayCastDelegates[elementType];
var instances = container.GetAllInstances(elementType).ToArray();
value = arrayCastDelegate(instances);
}
else
{
value = container.GetInstance(parameter.ParameterType);
}
return value;
}
示例5: ConfigureOnStartup
public void ConfigureOnStartup(IContainer container)
{
var dependenciesToInitialized = container.GetAllInstances<IRequireConfigurationOnStartup>();
foreach (var dependency in dependenciesToInitialized)
{
dependency.Configure();
}
}
示例6: Application_BeginRequest
public void Application_BeginRequest()
{
Container = ObjectFactory.Container.GetNestedContainer();
foreach (var task in Container.GetAllInstances<IRunOnEachRequest>())
{
task.Execute();
}
}
示例7: Register
public static void Register(IContainer container)
{
var mappingProfiles = container.GetAllInstances<Profile>();
foreach (var profile in mappingProfiles)
{
Mapper.AddProfile(profile);
}
}
示例8: ConfigureAutoMapper
private static void ConfigureAutoMapper(IContainer container)
{
var configuration = container.TryGetInstance<IConfiguration>();
if (configuration == null) return;
//saying AutoMapper how to resolve services
configuration.ConstructServicesUsing(container.GetInstance);
foreach (var profile in container.GetAllInstances<Profile>())
{
configuration.AddProfile(profile);
}
}
示例9: InitializeInternal
private static void InitializeInternal(IContainer container)
{
Mapper.Initialize(cfg =>
{
foreach (var profile in container.GetAllInstances<Profile>())
{
cfg.AddProfile(profile);
}
cfg.ConstructServicesUsing(container.GetInstance);
});
}
示例10: RegisterDocumentStores
internal UniformConfigurator RegisterDocumentStores(IContainer container)
{
UniformContext uniform = container.GetInstance<UniformContext>();
foreach (IDocument document in container.GetAllInstances<IDocument>())
{
Type documentType = document.GetType();
Type storeType = typeof (IDocumentStore<>).MakeGenericType(documentType);
MethodInfo method = uniform.GetType().GetMethod("GetDocumentStore").MakeGenericMethod(documentType);
container.Configure(config => config.For(storeType).Use(method.Invoke(uniform, null)));
}
return this;
}
示例11: buildProfile
private static IConventionProfile buildProfile(IContainer container, IEnumerable<Type> registries)
{
container.Configure(x =>
{
registries.Each(c => x.For(typeof (IConventionRegistry)).Add(c));
x.For<IConventionProfile>().Singleton().Use<ConventionProfile>();
});
var conventionProfile = container.GetInstance<IConventionProfile>();
foreach (var conventionRegistry in container.GetAllInstances<IConventionRegistry>())
{
conventionRegistry.Register(conventionProfile);
}
return conventionProfile;
}
示例12: AppContext
public AppContext(IContainer container)
{
_container = container;
var databaseService = _container.GetInstance<IDatabaseService>();
if (databaseService.IsServerConnectionOk())
{
foreach (var startupProcess in _container.GetAllInstances<IStartupProcess>())
{
startupProcess.Run();
}
MainForm = GetLoginForm();
}
else
{
MainForm = GetSqlServerConnectionForm();
}
}
示例13: RunOnServices
private static void RunOnServices(IContainer container, Action<IService> action, Action starting, Action finishing, Action<Exception> onError)
{
starting();
try
{
var services = container.GetAllInstances<IService>();
foreach (IService service in services)
{
action(service);
}
}
catch (Exception exception)
{
onError(exception);
throw;
}
finishing();
}
示例14: InitializeInternal
private static void InitializeInternal(IContainer container)
{
//var logger = Logger.Instance;
//logger.Debug("Initializing Automapper");
Mapper.Initialize(cfg =>
{
var profileNames = new List<string>();
foreach (var profile in container.GetAllInstances<Profile>())
{
profileNames.Add(profile.ProfileName);
cfg.AddProfile(profile);
}
//logger.Verbose("Added profiles: {ProfileName}", profileNames);
cfg.ConstructServicesUsing(container.GetInstance);
});
}
示例15: UseStructureMap
public static IBusCreator UseStructureMap(this BusConfiguration configuration, Assembly handlerAssembly, IContainer container)
{
if (configuration == null) throw new ArgumentNullException("configuration");
if (handlerAssembly == null) throw new ArgumentNullException("handlerAssembly");
if (container == null) throw new ArgumentNullException("container");
container.Configure(c =>
{
c.For<IBus>().HybridHttpOrThreadLocalScoped().Use<MsmqBus>();
c.Scan(a =>
{
a.Assembly(handlerAssembly);
a.AddAllTypesOf<IMessageHandler>().NameBy(t => t.FullName);
});
c.SetAllProperties(a => a.Matching(p => p.PropertyType == typeof(IBus)));
});
configuration.MessageCreator = container.GetInstance;
configuration.RegisterHandlers(container.GetAllInstances<IMessageHandler>().ToArray());
return new BusCreator(container);
}