本文整理汇总了C#中ILifetimeScope类的典型用法代码示例。如果您正苦于以下问题:C# ILifetimeScope类的具体用法?C# ILifetimeScope怎么用?C# ILifetimeScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILifetimeScope类属于命名空间,在下文中一共展示了ILifetimeScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetChildLifetimeScope
/// <summary>
/// Creates a new child scope or returns an existing child scope.
/// </summary>
/// <param name="parentScope">The current parent container.</param>
/// <param name="scopeKindTag">
/// A tag to identify this kind of scope so it can be reused to share objects
/// through fancy registration extensions (e.g. InstancePerSPSite, InstancePerSPWeb)
/// </param>
/// <param name="childScopeKey">A key to uniquely identify this scope within the container.</param>
/// <returns>The child scope for the uniquely identified resource</returns>
public ILifetimeScope GetChildLifetimeScope(ILifetimeScope parentScope, string scopeKindTag, string childScopeKey)
{
ILifetimeScope ensuredScope = null;
// Don't bother locking if the instance is already created
if (this.childScopes.ContainsKey(childScopeKey))
{
// Return the already-initialized container right away
ensuredScope = this.childScopes[childScopeKey];
}
else
{
// Only one scope should be registered at a time in this helper instance, to be on the safe side
lock (this.childScopesLockObject)
{
// Just in case, check again (because the assignment could have happened before we took hold of lock)
if (this.childScopes.ContainsKey(childScopeKey))
{
ensuredScope = this.childScopes[childScopeKey];
}
else
{
// This scope will never be disposed, i.e. it will live as long as the parent
// container, provided no one calls Dispose on it.
// The newly created scope is meant to sandbox InstancePerLifetimeScope-registered objects
// so that they get shared only within a boundary uniquely identified by the key.
ensuredScope = parentScope.BeginLifetimeScope(scopeKindTag);
this.childScopes[childScopeKey] = ensuredScope;
}
}
}
return ensuredScope;
}
示例2: WebApplicationComponent
//-----------------------------------------------------------------------------------------------------------------------------------------------------
public WebApplicationComponent(IWebAppEndpoint endpoint, Auto<ILogger> logger, IComponentContext componentContext)
{
_app = endpoint.Contract;
_address = endpoint.Address;
_logger = logger.Instance;
_container = (ILifetimeScope)componentContext;
}
示例3: AutofacDependencyResolver
/// <summary>
/// Initializes a new instance of the <see cref="AutofacDependencyResolver" /> class.
/// </summary>
/// <param name="lifetimeScope">The lifetime scope that services will be resolved from.</param>
/// <exception cref="System.ArgumentNullException">
/// Thrown if <paramref name="lifetimeScope" /> is <see langword="null" />.
/// </exception>
public AutofacDependencyResolver(ILifetimeScope lifetimeScope) {
if (lifetimeScope == null)
throw new ArgumentNullException("lifetimeScope");
_lifetimeScope = lifetimeScope;
_lifetimeScope.ComponentRegistry.AddRegistrationSource(this);
}
示例4: ApplicationStartup
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
pipelines.OnError.AddItemToEndOfPipeline((context, exception) =>
{
var message = string.Format("Exception: {0}", exception);
new ElmahErrorHandler.LogEvent(message).Raise();
return null;
});
pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx =>
{
var lang = ctx.Request.Headers.AcceptLanguage.FirstOrDefault();
if (lang != null)
{
// Accepted language can be something like "fi-FI", but it can also can be like fi-FI,fi;q=0.9,en;q=0.8
if (lang.Contains(","))
lang = lang.Substring(0, lang.IndexOf(","));
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
}
return null;
});
DoMigrations();
}
示例5: ApplicationStartup
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
// register interfaces/implementations
container.Update(builder => builder
//.RegisterType<CouchDbTShirtRepository>()
.RegisterType<MockedTShirtRepository>()
.As<ITShirtRepository>());
// register MyCouchStore parameter for couchdb repo classes
container.Update(builder => builder
.RegisterType<MyCouchStore>()
.As<IMyCouchStore>()
.UsingConstructor(typeof (string), typeof (string))
.WithParameters(new [] {
new NamedParameter("dbUri","http://seraya_dba:[email protected]:5984/"),
new NamedParameter("dbName","cshirts")
})
);
// TODO: remove after implementing REST-Api & replacing razor with angular
// display razor error messages
StaticConfiguration.DisableErrorTraces = false;
}
示例6: AutofacLifetimeScopeProvider
/// <summary>
/// 初始化一个 <see cref="AutofacLifetimeScopeProvider"/> 类的实例.
/// </summary>
/// <param name="container">
/// 容器.
/// </param>
public AutofacLifetimeScopeProvider(ILifetimeScope container)
{
Guard.ArgumentNotNull(() => container);
this.container = container;
AutofacRequestLifetimeHttpModule.SetLifetimeScopeProvider(this);
}
示例7: Rebuild
public Rebuild(IStoreEvents eventStore, IDomainUpdateServiceBusHandlerHook hook, ILifetimeScope container, IMongoContext mongo)
{
_eventStore = eventStore;
_hook = hook;
_container = container;
_mongo = mongo;
}
示例8: AutofacJobFactory
/// <summary>
/// Initializes a new instance of the <see cref="AutofacJobFactory" /> class.
/// </summary>
/// <param name="lifetimeScope">The lifetime scope.</param>
/// <param name="scopeName">Name of the scope.</param>
public AutofacJobFactory(ILifetimeScope lifetimeScope, string scopeName)
{
if (lifetimeScope == null) throw new ArgumentNullException("lifetimeScope");
if (scopeName == null) throw new ArgumentNullException("scopeName");
_lifetimeScope = lifetimeScope;
_scopeName = scopeName;
}
示例9: AutofacDependencyResolver
/// <summary>
/// Initializes a new instance of the <see cref="AutofacDependencyResolver" /> class.
/// </summary>
/// <param name="lifetimeScope">The lifetime scope that services will be resolved from.</param>
/// <exception cref="System.ArgumentNullException">
/// Thrown if <paramref name="lifetimeScope" /> is <see langword="null" />.
/// </exception>
public AutofacDependencyResolver(ILifetimeScope lifetimeScope)
{
if (lifetimeScope == null)
throw new ArgumentNullException("lifetimeScope");
_lifetimeScope = lifetimeScope;
}
示例10: RequestStartup
protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
{
// No registrations should be performed in here, however you may
// resolve things that are needed during request startup.
FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/account/login",
UserMapper = container.Resolve<IUserMapper>(),
});
pipelines.BeforeRequest.AddItemToEndOfPipeline(c =>
{
if (c.CurrentUser.IsAuthenticated())
{
container.Resolve<ITenantContext>().SetTenantId(c.CurrentUser.AsAuthenticatedUser().Id, c.CurrentUser.HasClaim("Admin"));
c.ViewBag.UserName = c.CurrentUser.AsAuthenticatedUser().FullName;
c.ViewBag.IsAdmin = c.CurrentUser.HasClaim("Admin");
}
else
container.Resolve<ITenantContext>().SetTenantId(null, false);
return null;
});
}
示例11: ConfigureApplicationContainer
protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
{
var setup = new Setup((IContainer)existingContainer);
// defaults
setup.WithGuidGenerator();
setup.WithThreadStaticTenantContext();
setup.WithMongo("MongoConnectionReadModel");
setup.RegisterReadModelRepositories();
// web specific
var builder = new ContainerBuilder();
builder.RegisterType<NancyUserMapper>().As<IUserMapper>();
builder.RegisterType<StaticContentResolverForInMemory>().As<IStaticContentResolver>();
builder.RegisterType<ExcelService>().As<IExcelService>();
builder.Update(setup.Container.ComponentRegistry);
// bus
setup.WithInMemoryBus();
setup.RegisterReadModelHandlers();
// eventstore
setup.WithMongoEventStore("MongoConnectionEventStore",
new AuthorizationPipelineHook(setup.Container),
new MessageDispatcher(setup.Container),
false);
// start the bus
setup.Container.Resolve<IServiceBus>().Start(ConfigurationManager.AppSettings["serviceBusEndpoint"]);
}
示例12: PluginHttpApi
public PluginHttpApi(
ILogger logger,
ILifetimeScope lifetimeScope)
{
_logger = logger;
_lifetimeScope = lifetimeScope;
}
示例13: ApplicationStartup
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
pipelines.OnError.AddItemToEndOfPipeline(LogException);
pipelines.BeforeRequest.AddItemToEndOfPipeline(DetectLanguage);
DoMigrations();
}
示例14: ConfigureApplicationContainer
protected override void ConfigureApplicationContainer(ILifetimeScope container)
{
base.ConfigureApplicationContainer(container);
var builder = new ContainerBuilder();
builder.RegisterType<AppSettings>().As<IAppSettings>().SingleInstance();
builder.RegisterType<DummyMailChimpWebhooks>().As<IMailChimpWebhooks>().SingleInstance();
builder.RegisterType<DummyMailgunWebhooks>().As<IMailgunWebhooks>().SingleInstance();
builder.RegisterType<AzureTableStorageTodoService>().As<ITodoService>().SingleInstance();
// Consumers and sagas
builder.RegisterAssemblyTypes(typeof(Bootstrapper).Assembly)
.Where(t => t.Implements<ISaga>() ||
t.Implements<IConsumer>())
.AsSelf();
// Saga repositories
builder.RegisterGeneric(typeof(InMemorySagaRepository<>))
.As(typeof(ISagaRepository<>))
.SingleInstance();
// Service bus
builder.Register(c => ServiceBusFactory.New(sbc =>
{
sbc.ReceiveFrom("loopback://localhost/queue");
sbc.Subscribe(x => x.LoadFrom(container));
})).As<IServiceBus>().SingleInstance();
builder.Update(container.ComponentRegistry);
}
示例15: Configure
public static HttpConfiguration Configure(IdentityServerOptions options, ILifetimeScope container)
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.SuppressDefaultHostAuthentication();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
config.Services.Add(typeof(IExceptionLogger), new LogProviderExceptionLogger());
config.Services.Replace(typeof(IHttpControllerTypeResolver), new HttpControllerTypeResolver());
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;
if (options.LoggingOptions.EnableWebApiDiagnostics)
{
var liblog = new TraceSource("LibLog");
liblog.Switch.Level = SourceLevels.All;
liblog.Listeners.Add(new LibLogTraceListener());
var diag = config.EnableSystemDiagnosticsTracing();
diag.IsVerbose = options.LoggingOptions.WebApiDiagnosticsIsVerbose;
diag.TraceSource = liblog;
}
ConfigureRoutes(options, config);
return config;
}