/// <summary> /// Registers a component by its type. The type used here is the type which will be instantiated when the component /// is resolved: The implementation of your component. /// </summary> /// <returns>A builder instance.</returns> /// <param name="concreteType">The implementation type of the component to be registered.</param> public IAsBuilderWithCacheability RegisterType(Type concreteType) { if (concreteType == null) { throw new ArgumentNullException(nameof(concreteType)); } ServiceRegistration registration; if (concreteType.GetTypeInfo().IsGenericTypeDefinition) { registration = new OpenGenericTypeRegistration(concreteType, constructorSelector) { ServiceType = concreteType }; } else { registration = new TypeRegistration(concreteType, constructorSelector) { ServiceType = concreteType }; } registrations.Add(registration); return(new RegistrationBuilder(registration)); }
public SignalConnectorType(TypeRegistration typeRegistration, string name, SWIGTYPE_p_f_p_Dali__BaseObject_p_Dali__ConnectionTrackerInterface_r_q_const__std__string_p_Dali__FunctorDelegate__bool func) : this(Interop.NDalic.new_SignalConnectorType(TypeRegistration.getCPtr(typeRegistration), name, SWIGTYPE_p_f_p_Dali__BaseObject_p_Dali__ConnectionTrackerInterface_r_q_const__std__string_p_Dali__FunctorDelegate__bool.getCPtr(func)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } }
public TypeRegistrationAssertion(TypeRegistration registration) { Assert.IsFalse(string.IsNullOrEmpty(registration.Name)); _registration = registration; _verifiedProperties = new HashSet <string>(); }
/// <summary> /// Registers the specified registration entry. It will add a component registration to Windsor /// container from an Enterprise Library TypeRegistration. /// </summary> /// <param name="registrationEntry">The registration entry.</param> private void Register(TypeRegistration registrationEntry) { // Get any dependencies (if any) for passing to Windsor registration. var dependencies = GetRegistrationDependencies(registrationEntry); // Create the actual registration from the entry and the dependencies. var registration = CreateComponent(registrationEntry, dependencies); try { m_container.Register(registration); } catch (ComponentRegistrationException) { // TODO: Find out why this happen (probably has to do with the registrationEntry values). // We are trying to register a component which is already registered by // the System.Type.FullName of the Castle.MicroKernel.Registration.ComponentRegistration<TService>.Implementation // HACK: Try to remove the component form the container and then register again using the TypeRegistration.Name as key. if (m_container.Kernel.RemoveComponent(registration.Name)) { registration = CreateComponent(registrationEntry, dependencies); m_container.Register(registration.Named(registrationEntry.Name)); } } }
public void ThenHasRegistrationForInstrumentationProvider() { TypeRegistration registration = registrations.Where(x => x.ServiceType == typeof(IAuthorizationProviderInstrumentationProvider)).FirstOrDefault(); Assert.IsNotNull(registration); Assert.AreEqual("Rule Provider", registration.Name); }
/// <inheritdoc/> protected override void Process(TypeRegistry registry, TypeRegistration registration, Type type) { if (type == null || registry.Contains(type)) { return; } if (!DomainTypeRegistry.IsInterestingType(type)) { return; } // The type is interesting; // If it is a persistent type, let's register all its bases if (DomainTypeRegistry.IsPersistentType(type)) { Process(registry, registration, type.BaseType); } Type[] interfaces = type.FindInterfaces( (_type, filterCriteria) => DomainTypeRegistry.IsPersistentType(_type), type); for (int index = 0; index < interfaces.Length; index++) { Process(registry, registration, interfaces[index]); } // Final registration base.Process(registry, registration, type); }
public void MatchingRuleHasTransientLifetime() { TagAttributeMatchingRuleData ruleData = new TagAttributeMatchingRuleData("RuleName", "TAg"); TypeRegistration registration = ruleData.GetRegistrations("").First(); Assert.AreEqual(TypeRegistrationLifetime.Transient, registration.Lifetime); }
public AnimatablePropertyComponentRegistration(TypeRegistration registered, string name, int index, int baseIndex, uint componentIndex) : this(Interop.NDalic.NewAnimatablePropertyComponentRegistration(TypeRegistration.getCPtr(registered), name, index, baseIndex, componentIndex), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } }
public AnimatablePropertyRegistration(TypeRegistration registered, string name, int index, PropertyType type) : this(Interop.NDalic.new_AnimatablePropertyRegistration__SWIG_0(TypeRegistration.getCPtr(registered), name, index, (int)type), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } }
public override void ScanAllOtherPlugins(TypeRegistration registration) { registration.PluginTypes.AssignableTo <IMessageConsumer>() .As <IMessageConsumer>() .AsSelf() .InstancePerLifetimeScope(); }
public AnimatablePropertyRegistration(TypeRegistration registered, string name, int index, PropertyValue value) : this(Interop.NDalic.NewAnimatablePropertyRegistration(TypeRegistration.getCPtr(registered), name, index, PropertyValue.getCPtr(value)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } }
public void TheRegistrationForILoggingUpdateCoordinatorIsForDefaultSingleton() { TypeRegistration registration = registrations.First(tr => tr.ServiceType == typeof(ILoggingUpdateCoordinator)); Assert.AreEqual(TypeRegistrationLifetime.Singleton, registration.Lifetime); Assert.IsTrue(registration.IsDefault); }
public void Visit_ResolvedTypedNamedValue() { // Set up EntLib. var registration = new TypeRegistration <RegisteredServiceConsumer>(() => new RegisteredServiceConsumer(EntLibContainer.Resolved <ISampleService>("named"))); var registrationParam = registration.ConstructorParameters.First(); Assert.IsType <ContainerResolvedParameter>(registrationParam); // Visit the parameter to get the Autofac equivalent. var ctorParam = this.GetCtorParam <RegisteredServiceConsumer>(typeof(ISampleService)); var visitor = new AutofacParameterBuilderVisitor(ctorParam); visitor.Visit(registrationParam); var result = visitor.AutofacParameter; Assert.NotNull(result); // Verify the converted parameter resolves correctly. var builder = new ContainerBuilder(); builder.RegisterType <RegisteredServiceConsumer>().UsingConstructor(typeof(ISampleService)).WithParameter(result); var named = new SampleServiceImpl(); builder.RegisterInstance(named).Named <ISampleService>("named"); var notNamed = new SampleServiceImpl(); builder.RegisterInstance(notNamed).As <ISampleService>(); var container = builder.Build(); var resolved = container.Resolve <RegisteredServiceConsumer>(); Assert.Same(named, resolved.CtorParameter); }
public void Registration_Should_Respect_SpecifiedLifeTime_Scoped() { var registration = new TypeRegistration <ClassA>(true, RegistrationLifetime.Scoped); new Bootstrapper().UseMicrosoftDependencyInjection(new ServiceCollection()).AddIoCRegistration(registration).Bootstrapp(); using (var scope = DIManager.BeginScope()) { var classA1 = scope.Resolve <ClassA>(); var classA2 = scope.Resolve <ClassA>(); ReferenceEquals(classA1, classA2).Should().BeTrue(); } ClassA outsideClass = null; using (var scope = DIManager.BeginScope()) { outsideClass = scope.Resolve <ClassA>(); } using (var scope = DIManager.BeginScope()) { var classA1 = scope.Resolve <ClassA>(); ReferenceEquals(classA1, outsideClass).Should().BeFalse(); } }
public void MatchingRuleHasTransientLifetime() { PropertyMatchingRuleData ruleData = new PropertyMatchingRuleData("Foo"); TypeRegistration registration = ruleData.GetRegistrations("").First(); Assert.AreEqual(TypeRegistrationLifetime.Transient, registration.Lifetime); }
public void Visit_ConstantValue() { // Set up EntLib. var registration = new TypeRegistration <RegisteredServiceConsumer>(() => new RegisteredServiceConsumer("abc")); var registrationParam = registration.ConstructorParameters.First(); Assert.IsInstanceOf <ConstantParameterValue>(registrationParam, "The parameter should have been seen by EntLib as a constant value."); // Visit the parameter to get the Autofac equivalent. var ctorParam = this.GetCtorParam <RegisteredServiceConsumer>(typeof(string)); var visitor = new AutofacParameterBuilderVisitor(ctorParam); visitor.Visit(registrationParam); var result = visitor.AutofacParameter; Assert.IsNotNull(result, "After visiting the registration value, the generated parameter should be set."); // Verify the converted parameter resolves correctly. var builder = new ContainerBuilder(); builder.RegisterType <RegisteredServiceConsumer>().UsingConstructor(typeof(string)).WithParameter(result); var container = builder.Build(); var resolved = container.Resolve <RegisteredServiceConsumer>(); Assert.AreEqual("abc", resolved.CtorParameter, "The constructor parameter was not properly set."); }
public void WithParametersFrom_NullRegistrar() { var registration = new TypeRegistration <RegisteredServiceConsumer>(() => new RegisteredServiceConsumer("abc")); IRegistrationBuilder <RegisteredServiceConsumer, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrar = null; Assert.Throws <ArgumentNullException>(() => registrar.WithParametersFrom(registration)); }
public void Given() { var configurationSource = new DictionaryConfigurationSource(); var oracleConnectionData = new OracleConnectionData { Name = "myConnectionName" }; oracleConnectionData.Packages.Add(new OraclePackageData("foo", "bar")); var oracleSettings = new OracleConnectionSettings(); oracleSettings.OracleConnectionsData.Add(oracleConnectionData); configurationSource.Add(OracleConnectionSettings.SectionName, oracleSettings); var databaseData = new OracleDatabaseData( new ConnectionStringSettings { Name = "myConnectionName", ConnectionString = "myConnectionString", ProviderName = "System.Data.Odbc" }, configurationSource); registration = databaseData.GetRegistrations().First(); }
public void RegisterTypeRegistration_NullTypeRegistration() { TypeRegistration registration = null; var builder = new ContainerBuilder(); Assert.Throws <ArgumentNullException>(() => builder.RegisterTypeRegistration(registration)); }
public void RegisterTypeRegistration_NullContainerBuilder() { var registration = new TypeRegistration <RegisteredServiceConsumer>(() => new RegisteredServiceConsumer("abc")); ContainerBuilder builder = null; Assert.Throws <ArgumentNullException>(() => builder.RegisterTypeRegistration(registration)); }
/// <summary> /// Creates the <see cref="TypeRegistration"/> entries to use when configuring a container for Exception Handling /// </summary> /// <returns></returns> public IEnumerable <TypeRegistration> GetRegistrations(IConfigurationSource configurationSource) { var registrations = new List <TypeRegistration>(); registrations.AddRange(GetDefaultInstrumentationRegistrations(configurationSource)); foreach (ExceptionPolicyData policyData in ExceptionPolicies) { registrations.AddRange(policyData.GetRegistration(configurationSource)); foreach (var policyTypeData in policyData.ExceptionTypes) { TypeRegistration policyTypeRegistration = policyTypeData.GetRegistration(policyData.Name); registrations.Add(policyTypeRegistration); registrations.AddRange( policyTypeData.ExceptionHandlers.SelectMany(ehd => ehd.GetRegistrations(policyTypeRegistration.Name))); } } TypeRegistration managerRegistration = GetManagerRegistration(ExceptionPolicies.Select(p => p.Name).ToArray()); managerRegistration.IsPublicName = true; registrations.Add(managerRegistration); return(registrations); }
internal TypeAction(TypeRegistration registered, string name, SWIGTYPE_p_f_p_Dali__BaseObject_r_q_const__std__string_r_q_const__Dali__Property__Map__bool f) : this(Interop.NDalic.new_TypeAction(TypeRegistration.getCPtr(registered), name, SWIGTYPE_p_f_p_Dali__BaseObject_r_q_const__std__string_r_q_const__Dali__Property__Map__bool.getCPtr(f)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } }
public void RegisterTypeRegistration_Default_WithEnumerationParameter() { var itemNames = new string[] { "first", "second", "third" }; var registration = new TypeRegistration<RegisteredServiceConsumer>(() => new RegisteredServiceConsumer(EntLibContainer.ResolvedEnumerable<ISampleService>(itemNames))); registration.IsDefault = true; registration.Lifetime = TypeRegistrationLifetime.Transient; var builder = new ContainerBuilder(); builder.RegisterTypeRegistration(registration); var first = new SampleServiceImpl(); builder.RegisterInstance(first).Named<ISampleService>("first"); var second = new SampleServiceImpl(); builder.RegisterInstance(second).Named<ISampleService>("second"); var third = new SampleServiceImpl(); builder.RegisterInstance(third).Named<ISampleService>("third"); var container = builder.Build(); var resolved = container.Resolve<RegisteredServiceConsumer>(); Assert.IsInstanceOf<IEnumerable<ISampleService>>(resolved.CtorParameter, "The constructor parameter was not the right type."); var services = ((IEnumerable<ISampleService>)resolved.CtorParameter).ToArray(); Assert.AreSame(first, services[0], "The first enumerable service was not resolved properly."); Assert.AreSame(second, services[1], "The second enumerable service was not resolved properly."); Assert.AreSame(third, services[2], "The third enumerable service was not resolved properly."); }
public void ThenRegistrationForCorrespondingInstrumentationProviderHasTransientLifetime() { var securityCacheProviderRegistrations = registrations.Where(x => x.ServiceType == typeof(ISecurityCacheProviderInstrumentationProvider)); TypeRegistration typeRegistration = securityCacheProviderRegistrations.First(); Assert.AreEqual(TypeRegistrationLifetime.Transient, typeRegistration.Lifetime); }
public void ThenRegistrationsConainRegistrationForCustomProvider() { TypeRegistration authProviderRegistration = registrations.Where(tr => tr.ServiceType == typeof(IAuthorizationProvider)).FirstOrDefault(); Assert.IsNotNull(authProviderRegistration); Assert.AreEqual(typeof(MockCustomAuthorizationProvider), authProviderRegistration.ImplementationType); }
public void Visit_ConstantValue() { // Set up EntLib. var registration = new TypeRegistration <RegisteredServiceConsumer>(() => new RegisteredServiceConsumer("abc")); var registrationParam = registration.ConstructorParameters.First(); Assert.IsType <ConstantParameterValue>(registrationParam); // Visit the parameter to get the Autofac equivalent. var ctorParam = this.GetCtorParam <RegisteredServiceConsumer>(typeof(string)); var visitor = new AutofacParameterBuilderVisitor(ctorParam); visitor.Visit(registrationParam); var result = visitor.AutofacParameter; Assert.NotNull(result); // Verify the converted parameter resolves correctly. var builder = new ContainerBuilder(); builder.RegisterType <RegisteredServiceConsumer>().UsingConstructor(typeof(string)).WithParameter(result); var container = builder.Build(); var resolved = container.Resolve <RegisteredServiceConsumer>(); Assert.Equal("abc", resolved.CtorParameter); }
public void ThenRegistrationsConainRegistrationForCustomProvider() { TypeRegistration securityCacheProvider = registrations.Where(tr => tr.ServiceType == typeof(ISecurityCacheProvider)).FirstOrDefault(); Assert.IsNotNull(securityCacheProvider); Assert.AreEqual(typeof(MockCustomSecurityCacheProvider), securityCacheProvider.ImplementationType); }
private static InjectionMember[] GetInjectionMembers(TypeRegistration registrationEntry) { List <InjectionMember> injectionMembers = new List <InjectionMember> { new InjectionConstructor( (from param in registrationEntry.ConstructorParameters select GetInjectionParameterValue(param)).ToArray()), }; injectionMembers.AddRange( (from prop in registrationEntry.InjectedProperties select new InjectionProperty( prop.PropertyName, GetInjectionParameterValue(prop.PropertyValue)) ).Cast <InjectionMember>() ); if (registrationEntry.IsDefault) { injectionMembers.Add(new DefaultInjectionMember { ServiceType = registrationEntry.ServiceType }); } return(injectionMembers.ToArray()); }
public PropertyRegistration(TypeRegistration registered, string name, int index, PropertyType type, SWIGTYPE_p_f_p_Dali__BaseObject_int_r_q_const__Dali__Property__Value__void setFunc, SWIGTYPE_p_f_p_Dali__BaseObject_Dali__Property__Index__Dali__Property__Value getFunc) : this(Interop.NDalic.NewPropertyRegistration(TypeRegistration.getCPtr(registered), name, index, (int)type, SWIGTYPE_p_f_p_Dali__BaseObject_int_r_q_const__Dali__Property__Value__void.getCPtr(setFunc), SWIGTYPE_p_f_p_Dali__BaseObject_Dali__Property__Index__Dali__Property__Value.getCPtr(getFunc)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } }
public void MatchingRuleHasTransientLifetime() { ReturnTypeMatchingRuleData ruleData = new ReturnTypeMatchingRuleData("RuleName", "System.Int32"); TypeRegistration registration = ruleData.GetRegistrations("").First(); Assert.AreEqual(TypeRegistrationLifetime.Transient, registration.Lifetime); }
public void WhenCreatingRegistrations_ThenCreatedTypeRegistrationHasTransientLifetime() { var typeRegistrations = cryptographySettings.GetRegistrations(null); TypeRegistration registration = typeRegistrations.Where(x => x.ServiceType == typeof(IHashProvider)).ElementAt(0); Assert.AreEqual(TypeRegistrationLifetime.Transient, registration.Lifetime); }
public void MatchingRuleHasTransientLifetime() { AssemblyMatchingRuleData asmMatchingRule = new AssemblyMatchingRuleData("RuleName", "mscorlib"); TypeRegistration registration = asmMatchingRule.GetRegistrations("").First(); Assert.AreEqual(TypeRegistrationLifetime.Transient, registration.Lifetime); }
private MutablePropertyValues getMutablePropertyValues(TypeRegistration registrationEntry) { MutablePropertyValues properties = new MutablePropertyValues(); foreach (InjectedProperty property in registrationEntry.InjectedProperties) { properties.Add(new PropertyValue(property.PropertyName,getInjectionParameterValue(property.PropertyValue))); } return properties; }
private void register(TypeRegistration registrationEntry) { AbstractObjectDefinition objDef = _factory.CreateObjectDefinition(registrationEntry.ImplementationType.AssemblyQualifiedName, null, AppDomain.CurrentDomain); objDef.PropertyValues = getMutablePropertyValues(registrationEntry); objDef.ConstructorArgumentValues = getConstructorArgumentValues(registrationEntry); IObjectFactory objectFactory = ((IConfigurableApplicationContext)_applicationContext).ObjectFactory; ((IObjectDefinitionRegistry)objectFactory).RegisterObjectDefinition(String.Concat(registrationEntry.Name,".",registrationEntry.ServiceType.Name), objDef); }
public void ShouldSetLifetime() { // Given const RegistrationLifetime lifetime = RegistrationLifetime.Scoped; // When var registration = new TypeRegistration(typeof(IService), typeof(ServiceOne), lifetime); // Then Assert.Equal(lifetime, registration.Lifetime); }
public void ShouldSetImplementationType() { // Given var implementationType = typeof(ServiceOne); // When var registration = new TypeRegistration(typeof(IService), implementationType, RegistrationLifetime.Transient); // Then Assert.Equal(implementationType, registration.ImplementationType); }
public void ShouldSetServiceType() { // Given var serviceType = typeof(IService); // When var registration = new TypeRegistration(serviceType, typeof(ServiceOne), RegistrationLifetime.Transient); // Then Assert.Equal(serviceType, registration.ServiceType); }
private ConstructorArgumentValues getConstructorArgumentValues(TypeRegistration registrationEntry) { ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues(); int index = 0; foreach (ParameterValue constructorParameter in registrationEntry.ConstructorParameters) { constructorArgs.AddIndexedArgumentValue(index++,getInjectionParameterValue(constructorParameter)); } return constructorArgs; }
/// <summary> /// Get the set of <see cref="TypeRegistration"/> object needed to /// register the CacheManager represented by this config element. /// </summary> /// <returns>The sequence of <see cref="TypeRegistration"/> objects.</returns> public virtual IEnumerable<TypeRegistration> GetRegistrations(IConfigurationSource configurationSource) { Expression<Func<ICacheManager>> newExpression = GetCacheManagerCreationExpression(); TypeRegistration cacheManagerRegistration = new TypeRegistration<ICacheManager>(newExpression) { Name = this.Name, IsPublicName = true }; return new TypeRegistration[] { cacheManagerRegistration }; }
void IObjectContainer.RegisterInstance(Type type, object instance, string name) { type.NotNull("type"); instance.NotNull("instance"); 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.RegisterInstance(type, name, instance); }
public void RegisterTypeRegistration_Default_NoParameters() { var registration = new TypeRegistration<RegisteredServiceConsumer>(() => new RegisteredServiceConsumer()); registration.IsDefault = true; registration.Lifetime = TypeRegistrationLifetime.Singleton; var builder = new ContainerBuilder(); builder.RegisterTypeRegistration(registration); var container = builder.Build(); var instance = container.Resolve<RegisteredServiceConsumer>(); Assert.AreEqual("DEFAULTCTOR", instance.CtorParameter, "The default constructor should have been invoked."); var instance2 = container.Resolve<RegisteredServiceConsumer>(); Assert.AreSame(instance, instance2, "The lifetime was not set on the registration."); }
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 bool ShouldReRegister(TypeRegistration updatedRegistration) { LifetimeInspector lifetimeInspector = container.Configure<LifetimeInspector>(); return !lifetimeInspector.HasResolvedLifetime( updatedRegistration.ImplementationType, updatedRegistration.Name); }
public void WhenCreatingATypeRegistrationWithANullService_ThenThrowsArgumentNull() { var registration = new TypeRegistration(expression, null); }
public void WhenTypeRegistrationCreatedWithImplementationForGenericParameter_ThenServieTypeIsNull() { TypeRegistration<Foo> registration = new TypeRegistration<Foo>(() => new Foo()); Assert.AreEqual(typeof(Foo), registration.ServiceType); }
private void FixupDefaultRegistration(TypeRegistration updatedRegistration) { var policyListAccessor = this.container.Configure<PolicyListAccessor>(); policyListAccessor.AddDefaultRegistration(updatedRegistration.ServiceType, updatedRegistration.ImplementationType, updatedRegistration.Name); }
public void Given() { expression = () => new TypeWithProperties { Property = "value", AnotherProperty = 42 }; registration = new TypeRegistration(expression); }
public void Given() { expression = () => new TypeWithProperties(new Foo()) { ResolvedProperty = Container.Resolved<IFoo>(), EnumerationResovledProperty = Container.ResolvedEnumerable<IFoo>(new string[] { "one", "two" }) }; registration = new TypeRegistration(expression); }
private static LifetimeManager CreateLifetimeManager(TypeRegistration registrationEntry) { if (registrationEntry.Lifetime == TypeRegistrationLifetime.Transient) { return new TransientLifetimeManager(); } return new ContainerControlledLifetimeManager(); }
public void Given() { expression = () => new TypeWithProperties { Property = "value", CollectionProperty = { "foo", "bar" } }; registration = new TypeRegistration<TypeWithProperties>(expression); }
public void Given() { expression = () => new TypeWithProperties { Property = "value", SomeOtherTypeWithProperties = { Property = "foo" } }; registration = new TypeRegistration<TypeWithProperties>(expression); }
public void Setup() { registration = new TypeRegistration<IFoo>(() => (IFoo)(new Foo { MyProperty = Container.Resolved<IBar>("some") })); }
public void Setup() { registration = new TypeRegistration<IFoo>( () => (IFoo)(new Foo("one", Container.Resolved<IBar>("two"), Container.Resolved<IBar>("three")))); }
public void Setup() { expression = () => new Foo(); registration = new TypeRegistration(expression); }
public void Setup() { registration = new TypeRegistration<IFoo>(() => (IFoo)(new Foo("some"))); }
public void Setup() { expression = () => new Foo( "aString", Container.Resolved<IBar>(), Container.ResolvedIfNotNull<IBar>(null)); registration = new TypeRegistration(expression); }
/// <summary> /// Returns the <see cref="TypeRegistration"/> entry for the actual trace listener represented by this /// configuration object. /// </summary> /// <returns>A registry entry.</returns> protected TypeRegistration GetTraceListenerTypeRegistration() { IEnumerable<MemberBinding> extraBindings; Expression creationExpression = GetCreationExpression().Body; NewExpression newExpression = creationExpression as NewExpression; if (newExpression != null) { extraBindings = new MemberBinding[0]; } else { MemberInitExpression memberInitExpression = creationExpression as MemberInitExpression; if (memberInitExpression != null) { newExpression = memberInitExpression.NewExpression; extraBindings = memberInitExpression.Bindings; } else { throw new NotSupportedException(Logging.Properties.Resources.ExceptionCreationLinqExpressionMustBeNew); } } MemberInitExpression memberInit = LambdaExpression.MemberInit(newExpression, GetSharedBindings().Concat(extraBindings)); TypeRegistration registration = new TypeRegistration<TraceListener>(LambdaExpression.Lambda<Func<TraceListener>>(memberInit)) { Name = this.WrappedTraceListenerName, Lifetime = TypeRegistrationLifetime.Transient }; return registration; }
/// <summary> /// Registers the <see cref="TypeRegistration"/> entry with the container. /// </summary> /// <param name="registrationEntry">The type registration entry to add to the container.</param> private void Register(TypeRegistration registrationEntry) { container.RegisterType( registrationEntry.ServiceType, registrationEntry.ImplementationType, registrationEntry.Name, CreateLifetimeManager(registrationEntry), GetInjectionMembers(registrationEntry)); }
private static InjectionMember[] GetInjectionMembers(TypeRegistration registrationEntry) { List<InjectionMember> injectionMembers = new List<InjectionMember> { new InjectionConstructor( (from param in registrationEntry.ConstructorParameters select GetInjectionParameterValue(param)).ToArray()), }; injectionMembers.AddRange( (from prop in registrationEntry.InjectedProperties select new InjectionProperty( prop.PropertyName, GetInjectionParameterValue(prop.PropertyValue)) ).Cast<InjectionMember>() ); if (registrationEntry.IsDefault) { injectionMembers.Add(new DefaultInjectionMember { ServiceType = registrationEntry.ServiceType }); } return injectionMembers.ToArray(); }
public void WhenRegistryTypeInstantiated_ThenThrowsArgumentException() { TypeRegistration registration = new TypeRegistration(expression); }