コード例 #1
0
        private static BasedOnDescriptor ApplyLifecycle(BasedOnDescriptor registration, Lifecycle lifecycle)
        {
            if (lifecycle.Name == Lifecycle.Singleton.Name)
                return registration.LifestyleSingleton();

            if (lifecycle.Name == Lifecycle.Transient.Name)
                return registration.LifestyleTransient();

            if (lifecycle.Name == Lifecycle.PerWebRequest.Name)
                return registration.LifestylePerWebRequest();

            if (lifecycle.Name == Lifecycle.Unmanaged.Name)
                return registration.LifestyleCustom<UnmanagedLifestyleManager>();

            if (lifecycle.Name == Lifecycle.Default.Name)
                return registration.LifestyleSingleton();

            if (lifecycle.Name == Lifecycle.ProviderDefault.Name)
                return registration;

            throw new ArgumentException(string.Format("Unknown Lifecycle : {0}", lifecycle), "lifecycle");
        }
コード例 #2
0
ファイル: CastleIoc.cs プロジェクト: kendarorg/Node.Cs.Old
		private BasedOnDescriptor InitializeLifeStyle(IClass component, BasedOnDescriptor componentFor)
		{
			switch (component.LifeStyle)
			{
				case (LifeStyle.Singleton):
					return componentFor.LifestyleSingleton();
				case (LifeStyle.Transient):
					return componentFor.LifestyleTransient();
				case (LifeStyle.WebRequest):
					return componentFor.LifestylePerWebRequest();
				case (LifeStyle.Pooled):
					return componentFor.LifestylePooled();
				default:
					throw new ContainerException("LifeStyle not allowed " + component.LifeStyle);
			}
		}