public void set_to_singleton()
        {
            #region sample_set-iconfigured-instance-to-SingletonThing
            IConfiguredInstance instance
                = new ConfiguredInstance(typeof(WidgetHolder));

            instance.Singleton();

            instance.Lifecycle.ShouldBeOfType <SingletonLifecycle>();
            #endregion
        }
        public void set_to_singleton()
        {
            // SAMPLE: set-iconfigured-instance-to-SingletonThing
            IConfiguredInstance instance
                = new ConfiguredInstance(typeof(WidgetHolder));

            instance.Singleton();

            instance.Lifecycle.ShouldBeOfType <SingletonLifecycle>();
            // ENDSAMPLE
        }
예제 #3
0
        public void Modify()
        {
            IConfiguredInstance instance =
                new ConfiguredInstance(typeof(ImportantService));


            instance.SetLifecycleTo(new SingletonLifecycle());

            instance.SetLifecycleTo <SingletonLifecycle>();

            instance.Singleton();
        }
예제 #4
0
        public static ConfiguredInstance SetLifeStyle(this ConfiguredInstance registration, LifetimeScope lifeTimeKey)
        {
            switch (lifeTimeKey)
            {
            case LifetimeScope.Unowned:
                return(registration.Transient());

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

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

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

            default:
                return(registration.Transient());
            }
        }
        public void set_to_default()
        {
            #region sample_iconfiguredinstance-lifecycle
            IConfiguredInstance instance
                = new ConfiguredInstance(typeof(WidgetHolder));

            // Use the SingletonThing lifecycle
            instance.Singleton();

            // or supply an ILifecycle type
            instance.SetLifecycleTo <ThreadLocalStorageLifecycle>();

            // or supply an ILifecycle object
            instance.SetLifecycleTo(new Lifecycles_Samples.MyCustomLifecycle());

            // or override to the default "transient" lifecycle
            instance.DefaultLifecycle();
            #endregion

            instance.Lifecycle
            .ShouldBeOfType <TransientLifecycle>();
        }
        public void set_to_default()
        {
            // SAMPLE: iconfiguredinstance-lifecycle
            IConfiguredInstance instance
                = new ConfiguredInstance(typeof(WidgetHolder));

            // Use the SingletonThing lifecycle
            instance.Singleton();

            // or supply an ILifecycle type
            instance.SetLifecycleTo <HttpContextLifecycle>();

            // or supply an ILifecycle object
            instance.SetLifecycleTo(new Lifecycles_Samples.MyCustomLifecycle());

            // or override to the default "transient" lifecycle
            instance.DefaultLifecycle();
            // ENDSAMPLE

            instance.Lifecycle
            .ShouldBeOfType <TransientLifecycle>();
        }