public static IRegistrationBuilder RegisterComponent( this ContainerBuilder cb, Service service, ActivationRegistrationData activationData) { if (cb == null) { throw new ArgumentNullException(nameof(cb)); } if (service == null) { throw new ArgumentNullException(nameof(service)); } if (activationData == null) { throw new ArgumentNullException(nameof(activationData)); } var builder = new RegistrationBuilder { Service = service, ActivationData = activationData }; cb.RegisterCallback( cr => { ValidateBuilderForComponent(builder); cr.Register( new ComponentRegistration( builder.Service, builder.ActivationData.Activator, builder.Lifetime, builder.Sharing)); }); return(builder); }
public static IRegistrationBuilder RegisterGeneric( this ContainerBuilder cb, Type genericType) { if (cb == null) { throw new ArgumentNullException(nameof(cb)); } if (genericType == null) { throw new ArgumentNullException(nameof(genericType)); } if (!genericType.IsGenericTypeDefinition) { throw new ArgumentException("Generic type should be a definition type."); } var builder = new RegistrationBuilder { Service = new TypedService(genericType), ActivationData = new ActivationRegistrationData(new ReflectiveActivator(genericType), genericType) }; cb.RegisterCallback( cr => { ValidateBuilderForGenericSource(builder); var openGenericRegistrationSource = new OpenGenericRegistrationSource( (IServiceWithType)builder.Service, builder.ActivationData.ImplementatorType, builder.Lifetime, builder.Sharing); cr.RegisterSource(openGenericRegistrationSource); }); return(builder); }
public static IRegistrationBuilder RegisterComponent( this ContainerBuilder cb, ComponentRegistration registration) { #region Please re-implement the code to pass the test /* * Since we have create a concrete type ComponentRegistry to manage the registion * work, all the registration operation can be considered as an action that add * somekind of component registration to the registry. * * In order to reuse the code, we re-implement the extension method to replace the * instance member function. */ var builder = new RegistrationBuilder { Service = registration.Service, Activator = registration.Activator }; cb.RegisterCallback(r => r.Register(builder.Build())); return(builder); #endregion }