本文整理汇总了C#中IComponentContext.BeginScope方法的典型用法代码示例。如果您正苦于以下问题:C# IComponentContext.BeginScope方法的具体用法?C# IComponentContext.BeginScope怎么用?C# IComponentContext.BeginScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IComponentContext
的用法示例。
在下文中一共展示了IComponentContext.BeginScope方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EventAutomation
public EventAutomation(IComponentContext context, EventAutomationSettings settings)
{
Guard.NotNull(() => context, context);
Guard.NotNull(() => settings, settings);
this.scope = context.BeginScope(c => { });
// TODO: see how to make this generic and not tied to Autofac somehow?
((ComponentContext)scope).Scope.ComponentRegistry.AddRegistrationSource(this);
this.binding = scope.Resolve<IBindingFactory>()
.CreateBinding<IObservable<IEventPattern<object, EventArgs>>>(scope, settings.Binding);
this.binding.Refresh();
this.subscription = this.binding.Instance.Subscribe(OnEvent);
if (settings.CommandSettings != null)
command = new Lazy<ICommandAutomation>(() => settings.CommandSettings.CreateAutomation(scope));
}
示例2: InstantiateProduct
/// <summary>
/// Simulates runtime behavior.
/// </summary>
private static Product InstantiateProduct(IComponentContext context)
{
var schema = context.Resolve<IToolkitCatalog>().Toolkits.First().Products.First();
// User instantiates a product via Solution Builder:
var product = new Product("MyWebService", typeof(IAmazonWebServices).FullName);
ComponentMapper.SyncProduct(product, schema);
var productContext = context.BeginScope(b => b.RegisterInstance(product));
foreach (var setting in schema.Automations)
{
product.AddAutomation(setting.CreateAutomation(productContext));
}
return product;
}