本文整理汇总了C#中ILifetimeScope.BeginLifetimeScope方法的典型用法代码示例。如果您正苦于以下问题:C# ILifetimeScope.BeginLifetimeScope方法的具体用法?C# ILifetimeScope.BeginLifetimeScope怎么用?C# ILifetimeScope.BeginLifetimeScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILifetimeScope
的用法示例。
在下文中一共展示了ILifetimeScope.BeginLifetimeScope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PingHub
public PingHub(ILifetimeScope lifetimeScope)
{
// Create a lifetime scope for this hub instance.
_hubLifetimeScope = lifetimeScope.BeginLifetimeScope();
// Resolve the dependencies from the hub lifetime scope (unfortunately, service locator style).
_bar = _hubLifetimeScope.Resolve<IBar>();
_foo = _hubLifetimeScope.Resolve<IFoo>();
}
示例2: NotificationHub
public NotificationHub(ILifetimeScope scope)
: base()
{
var lifetimeScope = scope.BeginLifetimeScope("AutofacWebRequest");
this.gameService = lifetimeScope.Resolve<IGameService>();
this.unitOfWork = lifetimeScope.Resolve<IUnitOfWork>();
this.userManager = lifetimeScope.Resolve<UserManager<User>>();
}
示例3: SimulateRequest
private static void SimulateRequest(ILifetimeScope rootLifetimeScope)
{
using (var requestLifetimeScope = rootLifetimeScope.BeginLifetimeScope())
{
var consumer = requestLifetimeScope.Resolve<ServiceConsumer>();
Console.WriteLine(consumer.DoSomething());
}
}
示例4: CommonHub
public CommonHub(ILifetimeScope lifetimeScope)
{
// Create a lifetime scope for the hub.
_hubLifetimeScope = lifetimeScope.BeginLifetimeScope();
// Resolve dependencies from the hub lifetime scope
_documentService = _hubLifetimeScope.Resolve<IDocumentsService>(); // singleton
_tableService = _hubLifetimeScope.Resolve<ITableService>(); // singleton
_counterService = _hubLifetimeScope.Resolve<IDistributedCounter>(); // singleton
}
示例5: InitializeLifetimeScope
static ILifetimeScope InitializeLifetimeScope(Action<ContainerBuilder> configurationAction, ILifetimeScope container)
{
return (configurationAction == null)
? container.BeginLifetimeScope(HttpRequestTag)
//, mp =>
//{
// mp.RegisterHttpRequestMessage(GlobalConfiguration.Configuration);
// // mp.Update(container.ComponentRegistry);
//})
: container.BeginLifetimeScope(HttpRequestTag, configurationAction);
}
示例6: UseAutofacMiddleware
public static IAppBuilder UseAutofacMiddleware(this IAppBuilder app, ILifetimeScope container)
{
app.Use(async (context, next) =>
{
using (var lifetimeScope = container.BeginLifetimeScope(Constants.LifetimeScopeTag,
b => b.RegisterInstance(context).As<IOwinContext>()))
{
context.Set(Constants.OwinLifetimeScopeKey, lifetimeScope);
await next();
}
});
return UseMiddlewareFromContainer(app, container);
}
示例7: DispatchCommit
private static void DispatchCommit(ILifetimeScope container, Commit commit)
{
using (var scope = container.BeginLifetimeScope())
{
NanoMessageBus.IPublishMessages publisher = scope.Resolve<NanoMessageBus.IPublishMessages>();
publisher.Publish(commit.Events.Select(e => e.Body).ToArray());
// need to complete and dispose the uow to do the actual publishing since
// the IHandleUnitOfWork is registered as ExternalyOwned
using (IHandleUnitOfWork uow = scope.Resolve<IHandleUnitOfWork>())
{
uow.Complete();
}
}
}
示例8: UseAutofacMiddleware
public static IAppBuilder UseAutofacMiddleware(this IAppBuilder app, ILifetimeScope container)
{
if (app == null) throw new ArgumentNullException("app");
if (app.Properties.ContainsKey(MiddlewareRegisteredKey)) return app;
app.Use(async (context, next) =>
{
using (var lifetimeScope = container.BeginLifetimeScope(Constants.LifetimeScopeTag,
b => b.RegisterInstance(context).As<IOwinContext>()))
{
context.Set(Constants.OwinLifetimeScopeKey, lifetimeScope);
await next();
}
});
UseMiddlewareFromContainer(app, container);
app.Properties.Add(MiddlewareRegisteredKey, true);
return app;
}
示例9: AppCore
/// <summary>
/// Создать область видимости приложения
/// </summary>
/// <param name="container">Контейнер области видимости приложения</param>
public AppCore(ILifetimeScope container) : base()
{
_rootScope = container;
Scope = _rootScope.BeginLifetimeScope(b =>
{
b.RegisterType<Config>()
.AsSelf()
.SingleInstance();
b.RegisterInstance(this)
.AsSelf()
.SingleInstance();
b.Register(c => this.BeginScope())
.As<IAppScope>()
.AsSelf();
b.RegisterModule<EmitImplementerModule>();
});
Instance = this;
}
示例10: UseAutofacMiddleware
public static IAppBuilder UseAutofacMiddleware(this IAppBuilder app, ILifetimeScope container)
{
if (app == null) throw new ArgumentNullException("app");
// idsvr : remove these guards so that multiple copies of middleware can be registered
//if (app.Properties.ContainsKey(MiddlewareRegisteredKey)) return app;
app.Use(async (context, next) =>
{
using (var lifetimeScope = container.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag,
b => b.RegisterInstance(context).As<IOwinContext>()))
{
context.Set(Constants.OwinLifetimeScopeKey, lifetimeScope);
await next();
}
});
UseMiddlewareFromContainer(app, container);
// idsvr : remove these guards so that multiple copies of middleware can be registered
//app.Properties.Add(MiddlewareRegisteredKey, true);
return app;
}
示例11: Setup
public void Setup()
{
_hostContainer = new ContainerBuilder().Build().BeginLifetimeScope(DreamContainerScope.Host);
_serviceContainer = _hostContainer.BeginLifetimeScope(DreamContainerScope.Service);
_requestContainer = _serviceContainer.BeginLifetimeScope(DreamContainerScope.Request);
}
示例12: InitializeLifetimeScope
static ILifetimeScope InitializeLifetimeScope(Action<ContainerBuilder> configurationAction, ILifetimeScope container)
{
return (configurationAction == null) ? container.BeginLifetimeScope(HttpRequestTag) : container.BeginLifetimeScope(HttpRequestTag, configurationAction);
}
示例13: BeginLifetimeScope
public static ILifetimeScope BeginLifetimeScope(ILifetimeScope scope, IMessageActivity message)
{
var inner = scope.BeginLifetimeScope(LifetimeScopeTag);
inner.Resolve<IMessageActivity>(TypedParameter.From(message));
return inner;
}
示例14: AutofacScope
protected AutofacScope(ILifetimeScope scope)
{
_scope = scope.BeginLifetimeScope();
}
示例15: ContentScope
public ContentScope(Type type, object key, ILifetimeScope parentScope, params Parameter[] parameters)
{
scope = parentScope.BeginLifetimeScope();
Content = scope.ResolveKeyed(key, type, parameters) as IContentViewModel;
}