/// <summary> /// Set scope based on <see cref="BindingLifecycle">ActivationScope</see> /// </summary> /// <param name="syntax"><see cref="IBindingInSyntax{T}">Binding syntax</see> to set the scope for</param> /// <param name="lifecycle"><see cref="BindingLifecycle"/> to use</param> public static void WithLifecycle <T>(this IBindingInSyntax <T> syntax, BindingLifecycle lifecycle) { switch (lifecycle) { case BindingLifecycle.Singleton: syntax.InSingletonScope(); break; #if (false) case BindingLifecycle.Request: syntax.InRequestScope(); break; #endif #if (NET461) case BindingLifecycle.Thread: syntax.InThreadScope(); break; #endif case BindingLifecycle.Transient: syntax.InTransientScope(); break; } }
public static IBindingNamedWithOrOnSyntax <T> InCommandScope <T>(this IBindingInSyntax <T> src, KernelMode mode) { return(mode switch { KernelMode.HangFireJob => src.InBackgroundJobScope(), KernelMode.Web => src.InRequestScope(), _ => throw new ArgumentOutOfRangeException(nameof(mode)) });
public static IBindingNamedWithOrOnSyntax <T> SetLifeStyle <T>(this IBindingInSyntax <T> registration, LifetimeScope lifeTimeKey) { switch (lifeTimeKey) { case LifetimeScope.Unowned: return(registration.InTransientScope()); case LifetimeScope.PerHttpRequest: return(registration.InRequestScope()); case LifetimeScope.PerThread: return(registration.InThreadScope()); default: return(registration.InTransientScope()); } }
public static IBindingNamedWithOrOnSyntax <T> ConfigureLifecycle <T>( this IBindingInSyntax <T> bindingInSyntax, ServiceLifetime lifecycleKind) { switch (lifecycleKind) { case ServiceLifetime.Singleton: return(bindingInSyntax.InSingletonScope()); case ServiceLifetime.Scoped: return(bindingInSyntax.InRequestScope()); case ServiceLifetime.Transient: return(bindingInSyntax.InTransientScope()); default: throw new NotSupportedException(); } }
/// <summary> /// Sets the scope using the given syntax. /// </summary> /// <param name="syntax">The syntax that is used to set the scope.</param> public void SetScope(IBindingInSyntax <object> syntax) { syntax.InRequestScope(); }
/// <summary> /// Sets the scope using the given syntax. /// </summary> /// <param name="syntax">The syntax that is used to set the scope.</param> public void SetScope(IBindingInSyntax<object> syntax) { syntax.InRequestScope(); }
/// <summary>Marks the registration as having a singleton scope for the lifetime of a http request.</summary> /// <value>The per request scoped.</value> /// TODO: Put this in a separate assembly as an extension method? Not all providers in all scenarios may support a dependency on System.Web (APN) public IInstanceRegistrarModifier <TContract> ScopedPerHttpRequest() { _bindingResult.InRequestScope(); return(this); }