private static void RegisterType(Type type, string name, Lifecycle lifecycle) { if (string.IsNullOrWhiteSpace(name) && TinyIoCContainer.Current.CanResolve(type)) { return; } if (!string.IsNullOrWhiteSpace(name) && TinyIoCContainer.Current.CanResolve(type, name)) { return; } TinyIoCContainer.RegisterOptions options; if (string.IsNullOrWhiteSpace(name)) { options = TinyIoCContainer.Current.Register(type); } else { options = TinyIoCContainer.Current.Register(type, name); } switch (lifecycle) { case Lifecycle.Singleton: options.AsSingleton(); break; case Lifecycle.Transient: options.AsMultiInstance(); break; case Lifecycle.PerSession: options.AsPerSession(); break; case Lifecycle.PerThread: options.AsPerThread(); break; } }
public RegisteredObject(Type typeToResolve, Func<IContainer, object> instanceExpression, Lifecycle lifecycle) { TypeToResolve = typeToResolve; InstanceExpression = instanceExpression; InstanceKey = Guid.NewGuid(); Lifecycle = lifecycle; }
public override void RegisterType(Type type, string name, Lifecycle lifecycle) { var lifetime = GetLifetimeManager(lifecycle); //var injectionMembers = InterceptionBehaviorMap.Instance.GetBehaviorTypes(type) // .Select(behaviorType => new InterceptionBehavior(behaviorType)) // .Cast<InterceptionMember>().ToList(); //if(injectionMembers.Count > 0) { // if(type.IsSubclassOf(typeof(MarshalByRefObject))) { // injectionMembers.Insert(0, new Interceptor<TransparentProxyInterceptor>()); // } // else { // injectionMembers.Insert(0, new Interceptor<VirtualMethodInterceptor>()); // } //} //if(type.IsDefined(typeof(HandlerAttribute), false) || // type.GetMembers().Any(item => item.IsDefined(typeof(HandlerAttribute), false))) { // int position = injectionMembers.Count > 0 ? 1 : 0; // injectionMembers.Insert(position, new InterceptionBehavior<PolicyInjectionBehavior>()); //} if(string.IsNullOrWhiteSpace(name)) { _container.RegisterType(type, lifetime); } else { _container.RegisterType(type, name, lifetime); } }
internal Registration(Type abstractType, Type concreteType, Func<IContainer, object> ctor, Lifecycle lifecycle, InjectionBehaviour injectionBehaviour) { this.AbstractType = abstractType; this.ConcreteType = concreteType; this.Ctor = ctor; this.Lifecycle = lifecycle; this.InjectionBehaviour = injectionBehaviour; }
public LifecycleSummary Summarize(Lifecycle lifecycle) { return new LifecycleSummary { Lifecycle = lifecycle, Successful = records.Where(x => x.specification.Lifecycle == lifecycle && x.WasSuccessful()).Count(), Failed = records.Where(x => x.specification.Lifecycle == lifecycle && !x.WasSuccessful()).Count() }; }
public void changeState() { if (lifeCycle == Lifecycle.Alive) lifeCycle = Lifecycle.Dying; else if (lifeCycle == Lifecycle.Dying) lifeCycle = Lifecycle.Dead; else if (lifeCycle == Lifecycle.Dead) lifeCycle = Lifecycle.Decomposing; }
public override void RegisterType(Type type, string name, Lifecycle lifetime) { var register = builder.RegisterType(type); if (!string.IsNullOrEmpty(name)) { register.Named(name, type); } if (lifetime == Lifecycle.Singleton) { register.SingleInstance(); } }
public override void RegisterType(Type from, Type to, string name, Lifecycle lifetime) { //var builder = new ContainerBuilder(); var register = builder.RegisterType(to).As(from); if (!string.IsNullOrEmpty(name)) { register.Named(name, from); } if (lifetime == Lifecycle.Singleton) { register.SingleInstance(); } //builder.Update(container); }
public static ServletFacesContext GetFacesContext (FacesContextFactory facesContextFactory, ServletContext servletContext, ServletRequest servletRequest, ServletResponse servletResponse, Lifecycle lifecycle, HttpContext httpContext, string executionFilePath) { FacesContext oldFacesContex = FacesContext.getCurrentInstance (); FacesContext wrappedFacesContex = facesContextFactory.getFacesContext (servletContext, servletRequest, servletResponse, lifecycle); ExternalContext externalContext = new ServletExternalContext (wrappedFacesContex.getExternalContext (), httpContext, executionFilePath); ServletFacesContext context = new ServletFacesContext (wrappedFacesContex, externalContext, httpContext, oldFacesContex); return context; }
void IObjectContainer.RegisterType(Type type, string name, Lifecycle lifetime) { type.NotNull("type"); if(!type.IsClass || type.IsAbstract) { throw new ApplicationException(string.Format("the type of '{0}' must be a class and cannot be abstract.", type.FullName)); } var typeRegistration = new TypeRegistration(type, name); if(_registeredTypes.Contains(typeRegistration) || this.IsRegistered(type, name)) { throw new ApplicationException(string.Format("the type of '{0}' as name '{1}' has been registered.", type.FullName, name)); } _registeredTypes.Add(typeRegistration); this.RegisterType(type, name, lifetime); }
private static ComponentRegistration<object> ApplyLifecycle(ComponentRegistration<object> registration, Lifecycle lifecycle) { if (lifecycle.Name == Lifecycle.Singleton.Name) return registration.LifeStyle.Singleton; if (lifecycle.Name == Lifecycle.Transient.Name) return registration.LifeStyle.Transient; if (lifecycle.Name == Lifecycle.PerWebRequest.Name) return registration.LifeStyle.PerWebRequest; if (lifecycle.Name == Lifecycle.Unmanaged.Name) return registration.LifeStyle.Custom<UnmanagedLifestyleManager>(); if (lifecycle.Name == Lifecycle.Default.Name) return registration.LifeStyle.Singleton; if (lifecycle.Name == Lifecycle.ProviderDefault.Name) return registration; throw new ArgumentException(string.Format("Unknown Lifecycle : {0}", lifecycle), "lifecycle"); }
private static IRegistrationBuilder<object, IConcreteActivatorData, SingleRegistrationStyle> ApplyLifecycleSingle(IRegistrationBuilder<object, IConcreteActivatorData, SingleRegistrationStyle> registration, Lifecycle lifecycle) { if (lifecycle.Name == Lifecycle.Singleton.Name) return registration.SingleInstance(); if (lifecycle.Name == Lifecycle.Transient.Name) return registration.InstancePerDependency(); if (lifecycle.Name == Lifecycle.PerWebRequest.Name) return registration.InstancePerMatchingLifetimeScope("httpRequest"); if (lifecycle.Name == Lifecycle.Unmanaged.Name) return registration.ExternallyOwned(); if (lifecycle.Name == Lifecycle.Default.Name) return registration.SingleInstance(); if (lifecycle.Name == Lifecycle.ProviderDefault.Name) return registration; throw new ArgumentException(string.Format("Unknown Lifecycle : {0}", lifecycle), "lifecycle"); }
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"); }
private static GenericFamilyExpression ApplyLifecycle(GenericFamilyExpression registration, Lifecycle lifecycle) { if (lifecycle.Name == Lifecycle.Singleton.Name) return registration.Singleton(); if (lifecycle.Name == Lifecycle.Transient.Name) return registration.LifecycleIs(InstanceScope.PerRequest); if (lifecycle.Name == Lifecycle.PerWebRequest.Name) return registration.HttpContextScoped(); if (lifecycle.Name == Lifecycle.Unmanaged.Name) return registration; if (lifecycle.Name == Lifecycle.ProviderDefault.Name) return registration; if (lifecycle.Name == Lifecycle.Default.Name) return registration.Singleton(); throw new ArgumentException(string.Format("Unknown Lifecycle : {0}", lifecycle), "lifecycle"); }
public HandlerWrapper(IHandler handler) { this.handler = handler; this.handerType = handler.GetType(); this.lifetime = LifeCycleAttribute.GetLifecycle(handerType); }
/// <summary> /// Trys to get an instance from the registered lifecycle store, creating it if it dosent exist /// </summary> /// <param name="type"></param> /// <param name="lifecycle"></param> /// <param name="tempInstanceStore"></param> /// <param name="buildStack"></param> /// <returns></returns> IEnumerable GetOrCreateInstances(Type type, Lifecycle lifecycle, IInstanceStore tempInstanceStore, Stack<Type> buildStack) { switch (lifecycle) { case Lifecycle.Singleton: return this.GetOrCreateInstances(type, this.singletonInstanceStore, tempInstanceStore, buildStack); case Lifecycle.HttpContextOrThreadLocal: return this.GetOrCreateInstances(type, this.httpContextOrThreadLocalStore, tempInstanceStore, buildStack); case Lifecycle.HttpContextOrExecutionContextLocal: return this.GetOrCreateInstances(type, this.httpContextOrExecutionContextLocalStore, tempInstanceStore, buildStack); default: var typesToCreate = GetTypesToCreate(type, buildStack); return typesToCreate.Select(typeToCreate => this.GetInstance(typeToCreate, tempInstanceStore, buildStack)).ToArray(); } }
bool CanCreateDependency(Type dependeeType, Type requestedType, Lifecycle lifecycle, IInstanceStore tempInstanceStore, bool allowMultiple, Stack<Type> buildStack) { var registrations = this.GetRegistrationsFor(requestedType, tempInstanceStore).ToList(); if (registrations.Any()) { if (!allowMultiple && registrations.Count > 1) throw new ContainerException("Cannot create dependency `" + requestedType.AssemblyQualifiedName + "`, there are multiple concrete types registered for it.", buildStack); if (registrations[0].Lifecycle < lifecycle) throw new ContainerException("Cannot create dependency `" + requestedType.AssemblyQualifiedName + "`. It's lifecycle (" + registrations[0].Lifecycle + ") is shorter than the dependee's `" + dependeeType.AssemblyQualifiedName + "` (" + lifecycle + ")", buildStack); return true; } if (requestedType.IsGenericType) { var genericTypeDefinition = requestedType.GetGenericTypeDefinition(); return this.HasRegistrationsFor(genericTypeDefinition); } return false; }
public void Store <T>(T item, string cacheKey, Lifecycle lifecycle) { var cache = lifecycle.Get().FindCache(); cache.Set(cacheKey, item); }
/// <summary> /// 注册一个类型 /// </summary> public abstract void RegisterType(Type from, Type to, string name, Lifecycle lifetime);
/// <summary> /// 注册类型 /// </summary> public static void RegisterMultiple(this IObjectContainer that, IEnumerable <Type> registrationTypes, Type implementationType, Lifecycle lifecycle = Lifecycle.Singleton) { foreach (var registrationType in registrationTypes) { that.RegisterType(registrationType, implementationType, lifecycle); } }
/// <summary> /// 注册一个类型 /// </summary> /// <param name="that">容器</param> /// <param name="from">注册类型</param> /// <param name="to">目标类型</param> /// <param name="lifetime">生命周期</param> public static void RegisterType(this IObjectContainer that, Type from, Type to, Lifecycle lifetime = Lifecycle.Singleton) { that.RegisterType(from, to, (string)null, lifetime); }
public T Get <T>(string cacheKey, Lifecycle lifecycle) { var objectCache = lifecycle.Get().FindCache(); return((T)objectCache.Get(cacheKey)); }
public void It_should_upload_and_download_projects() { var environment1 = new Environment(new ElementIdentifier("env1"), CreateItem <string>()); var environment2 = new Environment(new ElementIdentifier("env2"), CreateItem <string>()); var projectGroup = new ProjectGroup(CreateItemWithRename <ElementIdentifier>(false), string.Empty); var libraryVariableSet = new LibraryVariableSet(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(), LibraryVariableSet.VariableSetContentType.Variables, Enumerable.Empty <Variable>()); var lifecycle = new Lifecycle( CreateItemWithRename <ElementIdentifier>(false), string.Empty, new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items), new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items), Enumerable.Empty <Phase>()); var deploymentProcess = new DeploymentProcess(new List <DeploymentStep> { new DeploymentStep(CreateItem <string>(), CreateItem <DeploymentStep.StepCondition>(), CreateItem <bool>(), CreateItem <DeploymentStep.StepStartTrigger>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new [] { new DeploymentAction(CreateItem <string>(), CreateItem <string>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new [] { new ElementReference("env1") }), new DeploymentAction(CreateItem <string>(), CreateItem <string>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new [] { new ElementReference("env2") }) }), new DeploymentStep(CreateItem <string>(), CreateItem <DeploymentStep.StepCondition>(), CreateItem <bool>(), CreateItem <DeploymentStep.StepStartTrigger>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new [] { new DeploymentAction(CreateItem <string>(), CreateItem <string>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new [] { new ElementReference("env1") }) }) }); var scope = new Dictionary <VariableScopeType, IEnumerable <ElementReference> > { { VariableScopeType.Environment, new[] { new ElementReference("env1"), new ElementReference("env2") } }, { VariableScopeType.Machine, new[] { new ElementReference("m1"), new ElementReference("m2") } }, { VariableScopeType.Role, new[] { new ElementReference("r1"), new ElementReference("r2") } }, { VariableScopeType.Action, deploymentProcess.DeploymentSteps.SelectMany(s => s.Actions.Select(a => a.Name)).Select(action => new ElementReference(action)).ToArray() } }; var variables = new[] { new Variable(CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <string>(), scope, CreateItem <VariablePrompt>()), new Variable(CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <string>(), scope, CreateItem <VariablePrompt>()) }; var project1 = new Project(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <bool>(), deploymentProcess, variables, new[] { new ElementReference(libraryVariableSet.Identifier.Name) }, new ElementReference(lifecycle.Identifier.Name), new ElementReference(projectGroup.Identifier.Name), CreateItem <VersioningStrategy>(), Enumerable.Empty <ProjectTrigger>()); var project2 = new Project(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <bool>(), deploymentProcess, variables, new[] { new ElementReference(libraryVariableSet.Identifier.Name) }, new ElementReference(lifecycle.Identifier.Name), new ElementReference(projectGroup.Identifier.Name), null, new[] { CreateProjectTrigger("m1", "env1"), CreateProjectTrigger("m2", "env2") }); var expected = new SystemModelBuilder() .AddProject(project1) .AddProject(project2) .AddProjectGroup(projectGroup) .AddLifecycle(lifecycle) .AddLibraryVariableSet(libraryVariableSet) .AddEnvironment(environment1) .AddEnvironment(environment2) .Build(); _repository.Machines.Create(new MachineResource { Name = "m1" }); _repository.Machines.Create(new MachineResource { Name = "m2" }); _repository.FakeMachineRoles.Add("r1"); _repository.FakeMachineRoles.Add("r2"); _uploader.UploadModel(expected); var actual = _downloader.DownloadModel(); actual.AssertDeepEqualsTo(expected); }
private BrowserConfiguration GetCurrentBrowserConfiguration(Bellatrix.Plugins.PluginEventArgs e) { var browserAttribute = GetBrowserAttribute(e.TestMethodMemberInfo, e.TestClassType); string fullClassName = e.TestClassType.FullName; if (browserAttribute != null) { BrowserType currentBrowserType = browserAttribute.Browser; Lifecycle currentLifecycle = browserAttribute.Lifecycle; bool shouldCaptureHttpTraffic = browserAttribute.ShouldCaptureHttpTraffic; bool shouldAutomaticallyScrollToVisible = browserAttribute.ShouldAutomaticallyScrollToVisible; Size currentBrowserSize = browserAttribute.Size; ExecutionType executionType = browserAttribute.ExecutionType; var options = (browserAttribute as IDriverOptionsAttribute)?.CreateOptions(e.TestMethodMemberInfo, e.TestClassType) ?? GetDriverOptionsBasedOnBrowser(currentBrowserType, e.TestClassType); InitializeCustomCodeOptions(options, e.TestClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentLifecycle, currentBrowserType, currentBrowserSize, fullClassName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); e.Container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } else { BrowserType currentBrowserType = Parse <BrowserType>(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.DefaultBrowser); if (e.Arguments != null & e.Arguments.Any()) { if (e.Arguments[0] is BrowserType) { currentBrowserType = (BrowserType)e.Arguments[0]; } } Lifecycle currentLifecycle = Parse <Lifecycle>(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.DefaultLifeCycle); Size currentBrowserSize = default; if (!string.IsNullOrEmpty(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Resolution)) { currentBrowserSize = WindowsSizeResolver.GetWindowSize(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Resolution); } ExecutionType executionType = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.ExecutionType.ToLower() == "regular" ? ExecutionType.Regular : ExecutionType.Grid; bool shouldCaptureHttpTraffic = ConfigurationService.GetSection <WebSettings>().ShouldCaptureHttpTraffic; bool shouldAutomaticallyScrollToVisible = ConfigurationService.GetSection <WebSettings>().ShouldAutomaticallyScrollToVisible; var options = GetDriverOptionsBasedOnBrowser(currentBrowserType, e.TestClassType); if (!string.IsNullOrEmpty(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.BrowserVersion)) { options.BrowserVersion = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.BrowserVersion; } if (e.Arguments != null & e.Arguments.Count >= 2) { if (e.Arguments[0] is BrowserType && e.Arguments[1] is int) { options.BrowserVersion = e.Arguments[1].ToString(); } } string testName = e.TestFullName != null?e.TestFullName.Replace(" ", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty).Replace(",", string.Empty).Replace("\"", string.Empty) : e.TestClassType.FullName; InitializeGridOptionsFromConfiguration(options, e.TestClassType, testName); InitializeCustomCodeOptions(options, e.TestClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentLifecycle, currentBrowserType, currentBrowserSize, fullClassName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); e.Container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } }
/// <summary> /// Adds service type to container given a factory to create the type. /// </summary> /// <param name="serviceType"></param> /// <param name="implementationFactory"></param> /// <param name="lifeTime"></param> public virtual void Add(Type serviceType, Func <ILocator, object> implementationFactory, Lifecycle lifeTime) { _container.RegisterDelegate(serviceType, r => implementationFactory(r.Resolve <ILocatorAmbient>().Current), ConvertLifeTime(lifeTime)); }
/// <summary> /// Adds service type to container, given its implementation type via generics. /// </summary> /// <typeparam name="TService"></typeparam> /// <typeparam name="TImpl"></typeparam> /// <param name="key"></param> /// <param name="lifetime"></param> public virtual void Add <TService, TImpl>(string key = null, Lifecycle lifetime = Lifecycle.Transient) where TImpl : TService { RegisterSimple <TService, TImpl>(_container, _withResolvedArguments, ConvertLifeTime(lifetime), key); }
/// <summary> /// Adds service type to container, given its implementation type. /// </summary> /// <param name="serviceType"></param> /// <param name="serviceImplementation"></param> /// <param name="key"></param> /// <param name="lifetime"></param> public virtual void Add(Type serviceType, Type serviceImplementation, string key = null, Lifecycle lifetime = Lifecycle.Transient) { RegisterSimple(_container, serviceType, serviceImplementation, _withResolvedArguments, ConvertLifeTime(lifetime), key); }
/// <summary> /// 注册一个类型 /// </summary> /// <typeparam name="T">注册类型</typeparam> /// <param name="that">容器</param> /// <param name="lifetime">生命周期</param> public static void RegisterType <T>(this IObjectContainer that, Lifecycle lifetime = Lifecycle.Singleton) { that.RegisterType <T>((string)null, lifetime); }
/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (Name == null) { throw new ValidationException(ValidationRules.CannotBeNull, "Name"); } if (Env != null) { foreach (var element in Env) { if (element != null) { element.Validate(); } } } if (Lifecycle != null) { Lifecycle.Validate(); } if (LivenessProbe != null) { LivenessProbe.Validate(); } if (Ports != null) { foreach (var element1 in Ports) { if (element1 != null) { element1.Validate(); } } } if (ReadinessProbe != null) { ReadinessProbe.Validate(); } if (StartupProbe != null) { StartupProbe.Validate(); } if (VolumeDevices != null) { foreach (var element2 in VolumeDevices) { if (element2 != null) { element2.Validate(); } } } if (VolumeMounts != null) { foreach (var element3 in VolumeMounts) { if (element3 != null) { element3.Validate(); } } } }
public TestScreen(EventAggregator aggregator) : base(aggregator) { Lifecycle.RegisterHandler(ScreenEvents.Initialize <TSubject>(), HandleInitialize); }
public static void InitRuntime (ServletConfig config, object evidence) { ServletContext context = config.getServletContext (); if (context.getAttribute (J2EEConsts.APP_DOMAIN) != null) return; _facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory (FactoryFinder.FACES_CONTEXT_FACTORY); //TODO: null-check for Weblogic, that tries to initialize Servlet before ContextListener //Javadoc says: Lifecycle instance is shared across multiple simultaneous requests, it must be implemented in a thread-safe manner. //So we can acquire it here once: LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory (FactoryFinder.LIFECYCLE_FACTORY); _lifecycle = lifecycleFactory.getLifecycle (context.getInitParameter (FacesServlet.LIFECYCLE_ID_ATTR) ?? LifecycleFactory.DEFAULT_LIFECYCLE); _renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory (FactoryFinder.RENDER_KIT_FACTORY); AppDomain servletDomain = createServletDomain (config); [email protected] (servletDomain); try { //GH Infromation Initizalization long currentTime = java.lang.System.currentTimeMillis (); servletDomain.SetData (".domainId", currentTime.ToString ("x")); currentTime = ~currentTime; servletDomain.SetData (".appId", currentTime.ToString ("x")); servletDomain.SetData (".appName", servletDomain.SetupInformation.ApplicationName); servletDomain.SetData (J2EEConsts.CLASS_LOADER, java.lang.Thread.currentThread ().getContextClassLoader ()); //servletDomain.SetData (J2EEConsts.CLASS_LOADER, vmw.common.TypeUtils.ToClass (evidence).getClassLoader ()); //servletDomain.SetData(J2EEConsts.SERVLET_CONFIG, config); servletDomain.SetData (J2EEConsts.RESOURCE_LOADER, new ServletResourceLoader (context)); lock (evidence) { if (context.getAttribute (J2EEConsts.APP_DOMAIN) == null) context.setAttribute (J2EEConsts.APP_DOMAIN, servletDomain); } //config.getServletContext ().setAttribute (J2EEConsts.CURRENT_SERVLET, this); } finally { [email protected] (); [email protected] (); } }
public void Register(Type abstractType, Type concreteType, Lifecycle lifecycle = Lifecycle.Singleton) { if (!concreteType.IsOrDerivesFrom(abstractType)) throw new ContainerException("Concrete type `" + concreteType.AssemblyQualifiedName + "` is not assignable to abstract type `" + abstractType.AssemblyQualifiedName + "`"); if (concreteType.IsInterface || concreteType.IsAbstract) throw new ContainerException("Concrete type `" + concreteType.AssemblyQualifiedName + "` is not a concrete type"); lock (this.mutex) { if (!this.registeredTypes.ContainsKey(abstractType)) this.registeredTypes.Add(abstractType, new List<Registration>()); this.registeredTypes[abstractType].Add(new Registration(abstractType, concreteType, null, lifecycle, InjectionBehaviour.Default)); } }
public ViewPagerAdapter(FragmentManager fragmentManager, Lifecycle lifecycle) : base(fragmentManager, lifecycle) { }
public void RemoveAllInstancesWithLifecycle(Lifecycle lifecycle) { switch (lifecycle) { case Lifecycle.HttpContextOrThreadLocal: this.httpContextOrThreadLocalStore.Clear(); break; case Lifecycle.HttpContextOrExecutionContextLocal: this.httpContextOrExecutionContextLocalStore.Clear(); break; case Lifecycle.Singleton: this.singletonInstanceStore.Clear(); this.Inject<IContainer>(this); break; case Lifecycle.Transient: throw new ArgumentException("Can't clear transient instances, they're transient!"); } }
public ScreenWithInterfaceSubject(EventAggregator aggregator) : base(aggregator) { Lifecycle.RegisterHandler(ScreenEvents.Initialize <ISubject>(), HandleInitialize); }
public void Clear(Lifecycle lifecycle) { var objectCache = lifecycle.Get().FindCache(); objectCache.Clear(); }
public void Register(Type abstractType, Func<IContainer, object> ctor, Lifecycle lifecycle) { lock (this.mutex) { if (!this.registeredTypes.ContainsKey(abstractType)) this.registeredTypes.Add(abstractType, new List<Registration>()); this.registeredTypes[abstractType].Add(new Registration(abstractType, null, ctor, lifecycle, InjectionBehaviour.Default)); } }
public void As <TResult>(Lifecycle lifecycle = Lifecycle.Transient) where TResult : T { ConstructorCreater <T, TResult> creater = new ConstructorCreater <T, TResult>(DeclareMode.Explicit, lifecycle, _container); _container.AddCreater(creater); }
public void RemoveInstancesOf(Type type, Lifecycle lifecycle) { lock (this.mutex) { switch (lifecycle) { case Lifecycle.HttpContextOrThreadLocal: this.httpContextOrThreadLocalStore.RemoveInstances(type); return; case Lifecycle.HttpContextOrExecutionContextLocal: this.httpContextOrExecutionContextLocalStore.RemoveInstances(type); return; case Lifecycle.Singleton: this.singletonInstanceStore.RemoveInstances(type); return; case Lifecycle.Transient: throw new ArgumentException(); } } }
public void As <T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> func, Lifecycle lifecycle = Lifecycle.Transient) where TResult : T { FunctionCreater <T, TResult> creater = new FunctionCreater <T, TResult>(DeclareMode.Explicit, lifecycle, _container); creater.SetFunction(func); _container.AddCreater(creater); }
void CheckDependencies(Type dependeeType, IEnumerable<Type> parameters, Lifecycle lifecycle, IInstanceStore tempInstanceStore, Stack<Type> buildStack) { parameters.All(p => { if (CanCreateDependency(dependeeType, p, lifecycle, tempInstanceStore, false, buildStack)) return true; if (p.IsGenericType && p.GetGenericTypeDefinition() == typeof (IEnumerable<>)) return true; if (!p.IsAbstract && !p.IsInterface) return true; throw new ContainerException("Cannot create dependency `" + p.AssemblyQualifiedName + "` of dependee `" + dependeeType.AssemblyQualifiedName + "`", buildStack); }); }
public AppAttribute(string appPath, int width, int height, Lifecycle behavior = Lifecycle.NotSet) : this(appPath, behavior) { AppConfiguration.Size = new Size(width, height); }
public void Inject(object instance, Type type, Lifecycle lifeCycle, InjectionBehaviour injectionBehaviour) { if (lifeCycle == Lifecycle.Transient) throw new ArgumentException("You cannot inject an instance as Transient. That doesn't make sense, does it? Think about it..."); lock (this.mutex) { switch (lifeCycle) { case Lifecycle.Singleton: this.singletonInstanceStore.Inject(type, instance, injectionBehaviour); break; case Lifecycle.HttpContextOrThreadLocal: this.httpContextOrThreadLocalStore.Inject(type, instance, injectionBehaviour); break; case Lifecycle.HttpContextOrExecutionContextLocal: this.httpContextOrExecutionContextLocalStore.Inject(type, instance, injectionBehaviour); break; default: throw new NotSupportedException(); } } }
public AppAttribute(string appPath, DesktopWindowSize desktopWindowSize, Lifecycle behavior = Lifecycle.NotSet) : this(appPath, behavior) { AppConfiguration.Size = WindowsSizeResolver.GetWindowSize(desktopWindowSize); }
private static LifetimeManager GetLifetimeManager(Lifecycle lifecycle) { switch(lifecycle) { case Lifecycle.Singleton: return new ContainerControlledLifetimeManager(); default: return new TransientLifetimeManager(); } }
public FunctionCreater(DeclareMode delcareMode, Lifecycle lifecycle, Container container) { _declareMode = delcareMode; _lifecycle = lifecycle; _container = container; }
protected bool Equals(Lifecycle other) { return string.Equals(Name, other.Name); }
public void LifecycleChanged(Lifecycle lifecycle) { _filter.Lifecycle = lifecycle; ResetFilter(); }
public void Register <TClass>(Lifecycle lifecycle = Lifecycle.Transient) where TClass : class { container.Register <TClass>(lifecycleMapper[lifecycle]); }
void IObjectContainer.RegisterType(Type from, Type to, string name, Lifecycle lifetime) { from.NotNull("from"); to.NotNull("to"); if(!to.IsClass || to.IsAbstract) { throw new ApplicationException(string.Format("the type of '{0}' must be a class and cannot be abstract.", to.FullName)); } if(!from.IsAssignableFrom(to)) { throw new ApplicationException(string.Format("'{0}' does not extend '{1}'.", to.FullName, from.FullName)); } var typeRegistration = new TypeRegistration(from, name); if(_registeredTypes.Contains(typeRegistration) || this.IsRegistered(from, name)) { throw new ApplicationException(string.Format("the type of '{0}' as name '{1}' has been registered.", to.FullName, name)); } _registeredTypes.Add(typeRegistration); this.RegisterType(from, to, name, lifetime); }
public void Register <T>(Func <T> generator, Lifecycle lifecycle = Lifecycle.Transient) where T : class { container.Register(generator, lifecycleMapper[lifecycle]); }
void Start() { lifeCycle = Lifecycle.Alive; goatAttackMode = false; animator = this.GetComponent<Animator>(); beginningMovement = true; maxHealth = 0.5f; prevAttackingIndex = -1; // 1 out of 5 wolves will have 200% speed if( Random.Range(0, 100) <= 20 ) speed *= 2.0f; }
/// <summary> /// 注册一个类型 /// </summary> /// <typeparam name="T">注册类型</typeparam> /// <param name="that">容器</param> /// <param name="name">注册的名称</param> /// <param name="lifetime">生命周期</param> public static void RegisterType <T>(this IObjectContainer that, string name, Lifecycle lifetime = Lifecycle.Singleton) { name.NotWhiteSpace("name"); that.RegisterType(typeof(T), name, lifetime); }
/// <summary> /// 注册一个类型 /// </summary> /// <typeparam name="TFrom">注册类型</typeparam> /// <typeparam name="TTo">目标类型</typeparam> /// <param name="that">容器</param> /// <param name="name">注册的名称</param> /// <param name="lifetime">生命周期类型</param> public static void RegisterType <TFrom, TTo>(this IObjectContainer that, string name, Lifecycle lifetime = Lifecycle.Singleton) where TTo : TFrom { name.NotWhiteSpace("name"); that.RegisterType(typeof(TFrom), typeof(TTo), name, lifetime); }
internal static IFluentExportInstanceConfiguration <T> ConfigureLifetime <T>(this IFluentExportInstanceConfiguration <T> configuration, Lifecycle lifecycleKind) { switch (lifecycleKind) { case Lifecycle.Scoped: return(configuration.Lifestyle.SingletonPerScope()); case Lifecycle.Singleton: return(configuration.Lifestyle.Singleton()); } return(configuration); }
public void Register <TInterface, TClass>(Lifecycle lifecycle = Lifecycle.Transient) where TInterface : class where TClass : class, TInterface { container.Register <TInterface, TClass>(lifecycleMapper[lifecycle]); }
public static void ClearCache(Lifecycle lifecycle) { CacheProvider.Invoke().Clear(lifecycle); }
public TestCount(Lifecycle lifecycle) { Lifecycle = lifecycle; }
public void Register(Type interfaceType, Type implementationType, Lifecycle lifecycle = Lifecycle.Transient) { container.Register(interfaceType, implementationType, lifecycleMapper[lifecycle]); }