1414using System . Collections . Generic ;
1515using System . Linq ;
1616using System . Reflection ;
17+ using log4net . Core ;
18+ using Microsoft . Practices . Unity ;
19+ using System . Data . Entity . Core . Metadata . Edm ;
1720
1821namespace IntegrationEngine
1922{
2023 public class EngineHostConfiguration
2124 {
25+ public IUnityContainer Container { get ; set ; }
2226 public EngineConfiguration Configuration { get ; set ; }
2327 public IList < Type > IntegrationJobTypes { get ; set ; }
2428
@@ -28,6 +32,7 @@ public EngineHostConfiguration()
2832
2933 public void Configure ( IList < Assembly > assembliesWithJobs )
3034 {
35+ Container = ContainerSingleton . GetContainer ( ) ;
3136 IntegrationJobTypes = assembliesWithJobs
3237 . SelectMany ( x => x . GetTypes ( ) )
3338 . Where ( x => typeof ( IIntegrationJob ) . IsAssignableFrom ( x ) && x . IsClass )
@@ -60,19 +65,18 @@ static void TryAndLogFailure(string description, Action action)
6065 public void LoadConfiguration ( )
6166 {
6267 Configuration = new EngineConfiguration ( ) ;
63- Container . Register < EngineConfiguration > ( Configuration ) ;
68+ Container . RegisterInstance < EngineConfiguration > ( Configuration ) ;
6469 }
6570
6671 public void SetupLogging ( )
6772 {
6873 var log = log4net . LogManager . GetLogger ( System . Reflection . MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
69- Container . Register < ILog > ( log ) ;
74+ Container . RegisterInstance < ILog > ( log ) ;
7075 }
7176
7277 public void SetupDatabaseRepository ( )
7378 {
74- var dbContext = new DatabaseInitializer ( Configuration . Database ) . GetDbContext ( ) ;
75- Container . Register < IntegrationEngineContext > ( dbContext ) ;
79+ Container . RegisterInstance < IntegrationEngineContext > ( new DatabaseInitializer ( Configuration . Database ) . GetDbContext ( ) ) ;
7680 }
7781
7882 public void SetupApi ( )
@@ -87,7 +91,8 @@ public void SetupMailClient()
8791 MailConfiguration = Configuration . Mail ,
8892 Log = Container . Resolve < ILog > ( ) ,
8993 } ;
90- Container . Register < IMailClient > ( mailClient ) ;
94+
95+ Container . RegisterInstance < IMailClient > ( mailClient ) ;
9196 }
9297
9398 public void SetupMessageQueueListener ( )
@@ -96,6 +101,10 @@ public void SetupMessageQueueListener()
96101 IntegrationJobTypes = IntegrationJobTypes ,
97102 MessageQueueConnection = new MessageQueueConnection ( Configuration . MessageQueue ) ,
98103 MessageQueueConfiguration = Configuration . MessageQueue ,
104+ Log = Container . Resolve < ILog > ( ) ,
105+ MailClient = Container . Resolve < IMailClient > ( ) ,
106+ IntegrationEngineContext = Container . Resolve < IntegrationEngineContext > ( ) ,
107+ ElasticClient = Container . Resolve < IElasticClient > ( ) ,
99108 } ;
100109 rabbitMqListener . Listen ( ) ;
101110 }
@@ -105,17 +114,19 @@ public void SetupMessageQueueClient()
105114 var messageQueueClient = new RabbitMqClient ( ) {
106115 MessageQueueConnection = new MessageQueueConnection ( Configuration . MessageQueue ) ,
107116 MessageQueueConfiguration = Configuration . MessageQueue ,
117+ Log = Container . Resolve < ILog > ( ) ,
108118 } ;
109- Container . Register < IMessageQueueClient > ( messageQueueClient ) ;
119+ Container . RegisterInstance < IMessageQueueClient > ( messageQueueClient ) ;
110120 }
111121
112122 public void SetupScheduler ( )
113123 {
114124 var engineScheduler = new EngineScheduler ( ) {
115125 Scheduler = StdSchedulerFactory . GetDefaultScheduler ( ) ,
116126 IntegrationJobTypes = IntegrationJobTypes ,
127+ MessageQueueClient = Container . Resolve < IMessageQueueClient > ( ) ,
117128 } ;
118- Container . Register < IEngineScheduler > ( engineScheduler ) ;
129+ Container . RegisterInstance < IEngineScheduler > ( engineScheduler ) ;
119130 engineScheduler . Start ( ) ;
120131 var simpleTriggers = Container . Resolve < IElasticClient > ( ) . Search < SimpleTrigger > ( x => x ) . Documents ;
121132 var cronTriggers = Container . Resolve < IElasticClient > ( ) . Search < CronTrigger > ( x => x ) . Documents ;
@@ -131,7 +142,7 @@ public void SetupScheduler()
131142
132143 public void SetupRScriptRunner ( )
133144 {
134- Container . Register < RScriptRunner > ( new RScriptRunner ( ) ) ;
145+ Container . RegisterInstance < RScriptRunner > ( new RScriptRunner ( ) ) ;
135146 }
136147
137148 public void SetupElasticClient ( )
@@ -140,11 +151,12 @@ public void SetupElasticClient()
140151 var serverUri = new UriBuilder ( config . Protocol , config . HostName , config . Port ) . Uri ;
141152 var settings = new ConnectionSettings ( serverUri , config . DefaultIndex ) ;
142153 var elasticClient = new ElasticClient ( settings ) ;
143- Container . Register < IElasticClient > ( elasticClient ) ;
144- Container . Register < ESRepository < SimpleTrigger > > ( new ESRepository < SimpleTrigger > ( ) {
154+
155+ Container . RegisterInstance < IElasticClient > ( elasticClient ) ;
156+ Container . RegisterInstance < ESRepository < SimpleTrigger > > ( new ESRepository < SimpleTrigger > ( ) {
145157 ElasticClient = elasticClient
146158 } ) ;
147- Container . Register < ESRepository < CronTrigger > > ( new ESRepository < CronTrigger > ( ) {
159+ Container . RegisterInstance < ESRepository < CronTrigger > > ( new ESRepository < CronTrigger > ( ) {
148160 ElasticClient = elasticClient
149161 } ) ;
150162 }
0 commit comments