@@ -42,10 +42,11 @@ public void Configure(IList<Assembly> assembliesWithJobs)
4242 LoadConfiguration ( ) ;
4343 SetupLogging ( ) ;
4444 RegisterIntegrationPoints ( ) ;
45+ RegisterIntegrationJobs ( ) ;
4546 SetupRScriptRunner ( ) ;
4647 SetupElasticsearchRepository ( ) ;
47- SetupEngineScheduler ( ) ;
4848 SetupThreadedListenerManager ( ) ;
49+ SetupEngineScheduler ( ) ;
4950 SetupWebApi ( ) ;
5051 }
5152
@@ -76,10 +77,13 @@ public void RegisterIntegrationPoints()
7677 Container . RegisterType < INestSerializer , NestSerializer > ( ) ;
7778 Container . RegisterType < Elasticsearch . Net . Connection . ITransport , Elasticsearch . Net . Connection . Transport > ( ) ;
7879 Container . RegisterType < IConnectionSettingsValues , ConnectionSettings > ( ) ;
80+ //Container.RegisterType<IMailConfiguration, MailConfiguration>();
7981 foreach ( var config in EngineConfiguration . IntegrationPoints . Mail ) {
8082 Container . RegisterInstance < IMailConfiguration > ( config . IntegrationPointName , config ) ;
8183 Container . RegisterType < IMailClient , MailClient > ( config . IntegrationPointName , new InjectionConstructor ( config ) ) ;
8284 }
85+ var mailClientConfig = Container . Resolve < IMailConfiguration > ( "FooMailClient" ) ;
86+
8387 foreach ( var config in EngineConfiguration . IntegrationPoints . Elasticsearch ) {
8488 Container . RegisterInstance < IElasticsearchConfiguration > ( config . IntegrationPointName , config ) ;
8589 var serverUri = new UriBuilder ( config . Protocol , config . HostName , config . Port ) . Uri ;
@@ -100,6 +104,52 @@ public void RegisterIntegrationPoints()
100104 }
101105 }
102106
107+ public void RegisterIntegrationJobs ( )
108+ {
109+ foreach ( var jobType in IntegrationJobTypes )
110+ {
111+ // Register the Types with the Container
112+ // Register a constructor with the Container
113+ // Need to know which constructor should be used.
114+ // If it has no constructor, assume default constructor
115+ // If it has one constructor, then use that constructor
116+ // If it has two or more constructors use the first one with arguments
117+ var constructorCount = jobType . GetConstructors ( ) . Count ( ) ;
118+ if ( constructorCount <= 1 )
119+ {
120+ Container . RegisterType ( jobType ) ;
121+ continue ;
122+ }
123+ //else if (constructorCount >= 2)
124+ //{
125+ var parameters = jobType . GetConstructors ( ) . Single ( x => x . GetParameters ( ) . Any ( ) ) . GetParameters ( ) ;
126+ // Resolve the integration point type (in parameters).
127+ // Configure the integration point type with a configuration, based on the parameter name.
128+ var resolvedParameters = new List < ResolvedParameter > ( ) ;
129+ foreach ( var parameterInfo in parameters )
130+ {
131+ var parameterType = parameterInfo . ParameterType ; // The type of integration point (e.g. IElasticClient)
132+ var parameterName = parameterInfo . ParameterType . Name ; // The name of the configuration endpoint (e.g. "MyElasticClient")
133+
134+ if ( typeof ( IMailClient ) . IsAssignableFrom ( parameterType ) )
135+ {
136+ // Register the integration point.
137+ // To register the integration point, the parameters of the type's constructor must be known.
138+ // To make this happen, an integration point must have a constructor that takes a configuration object parameter.
139+ //var configName = parameterType.GetCustomAttribute<IntegrationPointConfigurationAttribute>().Name;
140+ //var config = Container.Resolve<IMailConfiguration>(parameterName);
141+ //Container.RegisterType(parameterType, new InjectionConstructor(config));
142+
143+ //Container.RegisterType<IMailClient, MailClient>(config.IntegrationPointName, new InjectionConstructor(config));
144+ Container . RegisterType ( parameterType , typeof ( MailClient ) ) ;
145+ resolvedParameters . Add ( new ResolvedParameter ( parameterType , parameterName ) ) ;
146+ }
147+ }
148+ var objectArray = resolvedParameters . Cast < object > ( ) . ToArray ( ) ;
149+ Container . RegisterType ( jobType , new InjectionConstructor ( objectArray ) ) ;
150+ }
151+ }
152+
103153 public void SetupThreadedListenerManager ( )
104154 {
105155 var config = Container . Resolve < IRabbitMQConfiguration > ( "DefaultRabbitMQ" ) ;
0 commit comments