public static ComponentRegistration <T> WithEndpoints <T>(this ComponentRegistration <T> r, IDictionary endpoints) where T : class { var explicitEndpoints = new Dictionary <string, Endpoint>(); var endpointNames = new Dictionary <string, string>(); foreach (var key in endpoints.Keys) { var dependencyName = key.ToString(); if (endpoints[key] is Endpoint) { var endpoint = (Endpoint)endpoints[key]; explicitEndpoints[dependencyName] = endpoint; } if (endpoints[key] is string) { var endpointName = (string)endpoints[key]; endpointNames[dependencyName] = endpointName; } } var componentRegistration = r.AddDescriptor(new CustomDependencyDescriptor(explicitEndpoints)); if (endpointNames.Count > 0) { componentRegistration.AddDescriptor(new WithEndpointsNamesDescriptor(endpointNames)); } return(componentRegistration); }
public static ComponentRegistration <T> WithEndpoints <T>(this ComponentRegistration <T> r, object endpoints) where T : class { var dictionary = new ReflectionBasedDictionaryAdapter(endpoints); var explicitEndpoints = new Dictionary <string, Endpoint>(); var endpointNames = new Dictionary <string, string>(); foreach (var key in dictionary.Keys) { var dependencyName = key.ToString(); if (dictionary[key] is Endpoint) { var endpoint = (Endpoint)dictionary[key]; explicitEndpoints[dependencyName] = endpoint; } if (dictionary[key] is string) { var endpointName = (string)dictionary[key]; endpointNames[dependencyName] = endpointName; } } return(r.AddDescriptor(new CustomDependencyDescriptor(explicitEndpoints)).ExtendedProperties(new { endpointNames })); }
public static ComponentRegistration PublishEvent(this ComponentRegistration registration, string eventName, Action <EventSubscribers> toSubscribers) { var subscribers = new EventSubscribers(); toSubscribers(subscribers); registration.AddDescriptor(new EventWiringDescriptor(eventName, subscribers.Subscribers)); return(registration); }
public static ComponentRegistration <TPublisher> PublishEvent <TPublisher>(this ComponentRegistration <TPublisher> registration, string eventName, Action <EventSubscribers> toSubscribers) where TPublisher : class { var subscribers = new EventSubscribers(); toSubscribers(subscribers); return(registration.AddDescriptor(new EventWiringDescriptor(eventName, subscribers.Subscribers))); }
private void RegisterComponent <T>(ComponentRegistration <T> componentRegistration, LifeStyle lifeStyle, bool isFallback) where T : class { var lifestyleDescriptor = new LifestyleDescriptor <T>(GetLifestyleType(lifeStyle)); componentRegistration.AddDescriptor(lifestyleDescriptor); if (isFallback) { componentRegistration = componentRegistration.IsFallback().NamedAutomatically(Guid.NewGuid().ToString()); } container.Register(componentRegistration); }
private static ComponentRegistration <TFactory> AttachConfiguration <TFactory>(ComponentRegistration <TFactory> componentRegistration, Action <TypedFactoryConfiguration> configuration, string defaultComponentSelectorKey) where TFactory : class { var selectorReference = GetSelectorReference(configuration, defaultComponentSelectorKey); return(componentRegistration .AddDescriptor(new ReferenceDependencyDescriptor(selectorReference)) .DynamicParameters((k, c, d) => { var selector = selectorReference.Resolve(k, c); d.Insert(selector); return k2 => k2.ReleaseComponent(selector); }) .AddAttributeDescriptor(TypedFactoryFacility.IsFactoryKey, "true")); }
private static ComponentRegistration <TFactory> AttachConfiguration <TFactory>( ComponentRegistration <TFactory> componentRegistration, Action <TypedFactoryConfiguration> configuration, string defaultComponentSelectorKey) where TFactory : class { var selectorReference = GetSelectorReference(configuration, defaultComponentSelectorKey, typeof(TFactory)); return(componentRegistration .AddDescriptor(new ReferenceDependencyDescriptor(selectorReference)) .DynamicParameters((k, context, args) => { var selector = selectorReference.Resolve(k, context); args.AddTyped(selector); return k2 => k2.ReleaseComponent(selector); }) .AddAttributeDescriptor(TypedFactoryFacility.IsFactoryKey, bool.TrueString)); }
public virtual void Apply(Component component, ComponentRegistration registration) { registration.AddDescriptor(this); }