public static TinyIoCContainer.RegisterOptions WithScopeFromRegistrationInfo(this TinyIoCContainer.RegisterOptions regOpts,
                                                                                     DependencyRegistration registration)
        {
            if (regOpts == null)
            {
                throw new ArgumentNullException(nameof(regOpts));
            }

            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            switch (registration.Scope)
            {
            case DependencyScope.Singleton:
                regOpts.AsSingleton();
                break;

            case DependencyScope.Thread:
                regOpts.AsPerRequestSingleton();
                break;

            case DependencyScope.Transient:
                if (!registration.IsProviderRegistration)
                {
                    regOpts.AsMultiInstance();
                }
                break;
            }

            return(regOpts);
        }
Exemple #2
0
 public static TinyIoCContainer.RegisterOptions Life(this TinyIoCContainer.RegisterOptions registration, LifeStyle life)
 {
     if (life == LifeStyle.Singleton)
     {
         return(registration.AsSingleton());
     }
     return(registration.AsMultiInstance());
 }
Exemple #3
0
        private static void ApplyOptions(TinyIoCContainer.RegisterOptions r, DefaultRegistrationBuilderBase instanceRegistration)
        {
            object scopeConfigObj;
            var    singleton = false;

            if (instanceRegistration.Options.TryGetValue("Singleton", out scopeConfigObj))
            {
                singleton = (bool)scopeConfigObj;
            }
            if (singleton)
            {
                r.AsSingleton();
            }
        }
 public void AsSingleton()
 {
     Debug.Assert(_registerOptions != null);
     _registerOptions.AsSingleton();
 }