private static ComponentRegistration <TDelegate> RegisterDelegateBasedFactory <TDelegate>( ComponentRegistration <TDelegate> registration, Action <TypedFactoryConfiguration> configuration, Type delegateType) where TDelegate : class { if (HasOutArguments(delegateType)) { throw new ComponentRegistrationException( string.Format("Delegate type {0} can not be used as typed factory because it has 'out' arguments.", delegateType)); } var invoke = DelegateFactory.ExtractInvokeMethod(delegateType); if (invoke == null) { throw new ComponentRegistrationException( string.Format("Delegate type {0} can not be used as typed factory because it has void return type.", delegateType)); } var settings = new TypedFactoryConfiguration(TypedFactoryFacility.DefaultDelegateSelectorKey, typeof(TDelegate)); if (configuration != null) { configuration.Invoke(settings); } var componentRegistration = AttachFactoryInterceptor(registration) .Activator <DelegateFactoryActivator>(); return(AttachConfiguration(componentRegistration, configuration, TypedFactoryFacility.DefaultDelegateSelectorKey)); }
private static IReference <ITypedFactoryComponentSelector> GetSelectorReference(Action <TypedFactoryConfiguration> configuration, string defaultComponentSelectorKey) { var factoryConfiguration = new TypedFactoryConfiguration(defaultComponentSelectorKey); if (configuration != null) { configuration.Invoke(factoryConfiguration); } return(factoryConfiguration.Reference); }
private static ComponentRegistration <TDelegate> RegisterDelegateBasedFactory <TDelegate>(ComponentRegistration <TDelegate> registration, Action <TypedFactoryConfiguration> configuration, Type delegateType) where TDelegate : class { if (HasOutArguments(delegateType)) { throw new ComponentRegistrationException( string.Format("Delegate type {0} can not be used as typed factory because it has 'out' arguments.", delegateType)); } var invoke = DelegateFactory.ExtractInvokeMethod(delegateType); if (invoke == null) { throw new ComponentRegistrationException( string.Format("Delegate type {0} can not be used as typed factory because it has void return type.", delegateType)); } var settings = new TypedFactoryConfiguration(TypedFactoryFacility.DefaultDelegateSelectorKey); if (configuration != null) { configuration.Invoke(settings); } var componentRegistration = AttachFactoryInterceptor(registration); componentRegistration.UsingFactoryMethod((k, m, c) => { var delegateProxyFactory = k.Resolve <IProxyFactoryExtension>(TypedFactoryFacility.DelegateProxyFactoryKey, new Arguments() .Insert("targetDelegateType", delegateType)); var @delegate = k.ProxyFactory.Create(delegateProxyFactory, k, m, c); k.ReleaseComponent(delegateProxyFactory); return((TDelegate)@delegate); }); return(AttachConfiguration(componentRegistration, configuration, TypedFactoryFacility.DefaultDelegateSelectorKey)); }