Exemple #1
0
        /// <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;
            }
        }
Exemple #2
0
 public static IBindingNamedWithOrOnSyntax<T> AsEagerSingleton<T>(this IBindingInSyntax<T> binding)
 {
     var r = binding.InSingletonScope();
     
     binding.Kernel.Bind<IEagerSingleton>().To<EagerSingleton<T>>().InSingletonScope();
     return r;
 }
Exemple #3
0
        /// <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;

            case BindingLifecycle.Transient:
                syntax.InTransientScope();
                break;
            }
        }
 /// <summary>
 ///     Sets the lifecycle.
 /// </summary>
 protected virtual void SetLifecycle(IBindingInSyntax <object> syntax, DependencyLifecycle lifecycle)
 {
     if (lifecycle == DependencyLifecycle.SingleInstance)
     {
         syntax.InSingletonScope();
         return;
     }
     if (lifecycle == DependencyLifecycle.TransientInstance)
     {
         syntax.InTransientScope();
         return;
     }
     Should.MethodBeSupported(false,
                              "SetLifecycle(IBindingInSyntax<object> syntax, DependencyLifecycle lifecycle)");
 }
Exemple #5
0
 private static void AddLifeStyleToRegistration <TInterface>(Lifestyle lifestyle, IBindingInSyntax <TInterface> registration)
 {
     if (lifestyle == Lifestyle.Singleton)
     {
         registration.InSingletonScope();
     }
     else if (lifestyle == Lifestyle.Transient)
     {
         registration.InTransientScope();
     }
     else
     {
         throw new ArgumentOutOfRangeException("lifestyle", "Only Transient and Singleton is supported");
     }
 }
Exemple #6
0
        private static IBindingNamedWithOrOnSyntax <object> InScope(this IBindingInSyntax <object> syntax, ServiceDescriptor s, ScopedBindingResolver scopeBindingResolver)
        {
            switch (s.Lifetime)
            {
            case ServiceLifetime.Singleton:
                return(syntax.InSingletonScope());

            case ServiceLifetime.Scoped:
                return(scopeBindingResolver(s, syntax));

            case ServiceLifetime.Transient:
                return(syntax.InTransientScope());
            }

            throw new Exception("Invalid service descriptor binding");
        }
        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();
            }
        }
Exemple #8
0
        private static void inScope(this IBindingInSyntax <object> to, ServiceLifetime lifetime)
        {
            switch (lifetime)
            {
            case ServiceLifetime.Singleton:
                to.InSingletonScope();
                break;

            case ServiceLifetime.Scoped:
                to.InScope(ctx => ctx.Kernel);
                break;

            case ServiceLifetime.Transient:
                to.InTransientScope();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null);
            }
        }
Exemple #9
0
        public static IBindingNamedWithOrOnSyntax <T> SetLifeStyle <T>(this IBindingInSyntax <T> registration, LifetimeScope lifeTimeKey)
        {
            switch (lifeTimeKey)
            {
            case LifetimeScope.Unowned:
                return(registration.InTransientScope());

            case LifetimeScope.Singleton:
                return(registration.InSingletonScope());

            case LifetimeScope.PerHttpRequest:
                return(registration.InTransientScope());

            case LifetimeScope.PerThread:
                return(registration.InThreadScope());

            default:
                return(registration.InTransientScope());
            }
        }
 /// <summary>
 ///     Sets the lifecycle.
 /// </summary>
 protected virtual void SetLifecycle(IBindingInSyntax<object> syntax, DependencyLifecycle lifecycle)
 {
     if (lifecycle == DependencyLifecycle.SingleInstance)
     {
         syntax.InSingletonScope();
         return;
     }
     if (lifecycle == DependencyLifecycle.TransientInstance)
     {
         syntax.InTransientScope();
         return;
     }
     Should.MethodBeSupported(false,
         "SetLifecycle(IBindingInSyntax<object> syntax, DependencyLifecycle lifecycle)");
 }
Exemple #11
0
 /// <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.InSingletonScope();
 }
Exemple #12
0
 /// <summary>Marks the registration as having a singleton scope.</summary>
 /// <returns>Itself</returns>
 public IInstanceRegistrarModifier <TContract> ScopedAsSingleton()
 {
     _bindingResult.InSingletonScope();
     return(this);
 }
 /// <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.InSingletonScope();
 }