コード例 #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;
            }
        }
コード例 #2
0
        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());
            }
        }
コード例 #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;
            }
        }
コード例 #4
0
 /// <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)");
 }
コード例 #5
0
ファイル: Container.cs プロジェクト: siimv/Agatha
 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");
     }
 }
コード例 #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");
        }
コード例 #7
0
        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();
            }
        }
コード例 #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);
            }
        }
コード例 #9
0
 /// <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)");
 }
コード例 #10
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.InTransientScope();
 }
コード例 #11
0
 public IInstanceRegistrarModifier <TContract> ScopedWithNestedLifetime()
 {
     //TODO: Check if NInject's transient scope is analogous to Autofac's ExternallyOwned
     _bindingResult.InTransientScope();
     return(this);
 }
コード例 #12
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.InTransientScope();
 }