@@ -16,7 +16,6 @@ namespace TransactionProcessor
1616 using System . IO ;
1717 using System . Net . Http ;
1818 using System . Reflection ;
19- using Autofac ;
2019 using BusinessLogic . OperatorInterfaces ;
2120 using BusinessLogic . OperatorInterfaces . SafaricomPinless ;
2221 using BusinessLogic . RequestHandlers ;
@@ -71,36 +70,34 @@ public void ConfigureServices(IServiceCollection services)
7170 this . ConfigureMiddlewareServices ( services ) ;
7271
7372 services . AddTransient < IMediator , Mediator > ( ) ;
74- }
7573
76- public void ConfigureContainer ( ContainerBuilder builder )
77- {
7874 ConfigurationReader . Initialise ( Startup . Configuration ) ;
7975 String connString = Startup . Configuration . GetValue < String > ( "EventStoreSettings:ConnectionString" ) ;
8076 String connectionName = Startup . Configuration . GetValue < String > ( "EventStoreSettings:ConnectionName" ) ;
8177 Int32 httpPort = Startup . Configuration . GetValue < Int32 > ( "EventStoreSettings:HttpPort" ) ;
8278
8379 Boolean useConnectionStringConfig = Boolean . Parse ( ConfigurationReader . GetValue ( "AppSettings" , "UseConnectionStringConfig" ) ) ;
8480 EventStoreConnectionSettings settings = EventStoreConnectionSettings . Create ( connString , connectionName , httpPort ) ;
85- builder . RegisterInstance ( settings ) ;
86-
87- Func < EventStoreConnectionSettings , IEventStoreConnection > eventStoreConnectionFunc = ( connectionSettings ) =>
88- {
89- return EventStoreConnection . Create ( connectionSettings . ConnectionString ) ;
90- } ;
81+ services . AddSingleton ( settings ) ;
9182
92- builder . RegisterInstance < Func < EventStoreConnectionSettings , IEventStoreConnection > > ( eventStoreConnectionFunc ) ;
83+ services . AddSingleton < Func < EventStoreConnectionSettings , IEventStoreConnection > > ( cont => ( connectionSettings ) =>
84+ {
85+ return EventStoreConnection . Create ( connectionSettings
86+ . ConnectionString ) ;
87+ } ) ;
9388
94- Func < String , IEventStoreContext > eventStoreContextFunc = ( connectionString ) =>
95- {
96- EventStoreConnectionSettings connectionSettings = EventStoreConnectionSettings . Create ( connectionString , connectionName , httpPort ) ;
89+ services . AddSingleton < Func < String , IEventStoreContext > > ( cont => ( connectionString ) =>
90+ {
91+ EventStoreConnectionSettings connectionSettings =
92+ EventStoreConnectionSettings . Create ( connectionString , connectionName , httpPort ) ;
9793
98- IEventStoreContext context = new EventStoreContext ( connectionSettings , eventStoreConnectionFunc ) ;
94+ Func < EventStoreConnectionSettings , IEventStoreConnection > eventStoreConnectionFunc = cont . GetService < Func < EventStoreConnectionSettings , IEventStoreConnection > > ( ) ;
9995
100- return context ;
101- } ;
96+ IEventStoreContext context =
97+ new EventStoreContext ( connectionSettings , eventStoreConnectionFunc ) ;
10298
103- builder . RegisterInstance < Func < String , IEventStoreContext > > ( eventStoreContextFunc ) ;
99+ return context ;
100+ } ) ;
104101
105102 SafaricomConfiguration safaricomConfiguration = new SafaricomConfiguration ( ) ;
106103
@@ -114,57 +111,67 @@ public void ConfigureContainer(ContainerBuilder builder)
114111 }
115112 }
116113
117- builder . RegisterInstance < SafaricomConfiguration > ( safaricomConfiguration ) ;
118-
114+ services . AddSingleton < SafaricomConfiguration > ( safaricomConfiguration ) ;
115+
119116 if ( useConnectionStringConfig )
120117 {
121118 String connectionStringConfigurationConnString = ConfigurationReader . GetConnectionString ( "ConnectionStringConfiguration" ) ;
122- builder . Register ( c => new ConnectionStringConfigurationContext ( connectionStringConfigurationConnString ) ) . InstancePerDependency ( ) ;
123- builder . RegisterType < ConnectionStringConfigurationRepository > ( ) . As < IConnectionStringConfigurationRepository > ( ) . SingleInstance ( ) ;
124- builder . RegisterType < EventStoreContextManager > ( ) . As < IEventStoreContextManager > ( ) . UsingConstructor ( typeof ( Func < String , IEventStoreContext > ) , typeof ( IConnectionStringConfigurationRepository ) ) . SingleInstance ( ) ;
119+ services . AddSingleton < IConnectionStringConfigurationRepository , ConnectionStringConfigurationRepository > ( ) ;
120+ services . AddTransient < ConnectionStringConfigurationContext > ( c =>
121+ {
122+ return new ConnectionStringConfigurationContext ( connectionStringConfigurationConnString ) ;
123+ } ) ;
124+
125+ services . AddSingleton < IEventStoreContextManager , EventStoreContextManager > ( c =>
126+ {
127+ Func < String , IEventStoreContext > contextFunc = c . GetService < Func < String , IEventStoreContext > > ( ) ;
128+ IConnectionStringConfigurationRepository connectionStringConfigurationRepository =
129+ c . GetService < IConnectionStringConfigurationRepository > ( ) ;
130+ return new EventStoreContextManager ( contextFunc ,
131+ connectionStringConfigurationRepository ) ;
132+ } ) ;
125133 }
126134 else
127135 {
128- builder . RegisterType < EventStoreContextManager > ( ) . As < IEventStoreContextManager > ( ) . UsingConstructor ( typeof ( IEventStoreContext ) ) . SingleInstance ( ) ;
129- // TODO: Once we have a Read Model
130- //this.RegisterType<Vme.Repositories.IConnectionStringRepository, ConfigReaderConnectionStringRepository>().Singleton();
136+ services . AddSingleton < IEventStoreContextManager , EventStoreContextManager > ( c =>
137+ {
138+ IEventStoreContext context = c . GetService < IEventStoreContext > ( ) ;
139+ return new EventStoreContextManager ( context ) ;
140+ } ) ;
141+ //services.AddSingleton<IConnectionStringConfigurationRepository, ConfigurationReaderConnectionStringRepository>();
131142 }
132143
133- builder . RegisterType < EventStoreContext > ( ) . As < IEventStoreContext > ( ) ;
134- builder . RegisterType < AggregateRepositoryManager > ( ) . As < IAggregateRepositoryManager > ( ) . SingleInstance ( ) ;
135- builder . RegisterType < AggregateRepository < TransactionAggregate . TransactionAggregate > > ( ) . As < IAggregateRepository < TransactionAggregate . TransactionAggregate > > ( ) . SingleInstance ( ) ;
136- builder . RegisterType < TransactionDomainService > ( ) . As < ITransactionDomainService > ( ) . SingleInstance ( ) ;
137- builder . RegisterType < Factories . ModelFactory > ( ) . As < Factories . IModelFactory > ( ) . SingleInstance ( ) ;
138- builder . RegisterType < EstateClient > ( ) . As < IEstateClient > ( ) . SingleInstance ( ) ;
139- builder . RegisterType < SecurityServiceClient > ( ) . As < ISecurityServiceClient > ( ) . SingleInstance ( ) ;
140- builder . RegisterType ( typeof ( HttpClient ) ) . SingleInstance ( ) ;
141- builder . Register < Func < String , String > > ( c => ( api ) =>
142- {
143- Uri uri = ConfigurationReader . GetBaseServerUri ( api ) ;
144- return uri . AbsoluteUri . Substring ( 0 , uri . AbsoluteUri . Length - 1 ) ;
145- } ) ;
146- builder . Register < Func < String , IOperatorProxy > > ( c =>
147- {
148- IComponentContext cx = c . Resolve < IComponentContext > ( ) ;
149- return operatorrIdentifier =>
150- {
151- SafaricomConfiguration configuration = cx . Resolve < SafaricomConfiguration > ( ) ;
152- HttpClient client = cx . Resolve < HttpClient > ( ) ;
153- return new SafaricomPinlessProxy ( configuration , client ) ;
154- } ;
155- } ) ;
156-
144+ services . AddTransient < IEventStoreContext , EventStoreContext > ( ) ;
145+ services . AddSingleton < IAggregateRepositoryManager , AggregateRepositoryManager > ( ) ;
146+ services . AddSingleton < IAggregateRepository < TransactionAggregate . TransactionAggregate > , AggregateRepository < TransactionAggregate . TransactionAggregate > > ( ) ;
147+ services . AddSingleton < ITransactionDomainService , TransactionDomainService > ( ) ;
148+ services . AddSingleton < Factories . IModelFactory , Factories . ModelFactory > ( ) ;
149+ services . AddSingleton < ISecurityServiceClient , SecurityServiceClient > ( ) ;
150+ services . AddSingleton < Func < String , String > > ( container => ( serviceName ) =>
151+ {
152+ return ConfigurationReader . GetBaseServerUri ( serviceName ) . OriginalString ;
153+ } ) ;
154+ services . AddSingleton < HttpClient > ( ) ;
155+ services . AddSingleton < IEstateClient , EstateClient > ( ) ;
157156 // request & notification handlers
158- builder . Register < ServiceFactory > ( context =>
159- {
160- IComponentContext c = context . Resolve < IComponentContext > ( ) ;
161- return t => c . Resolve ( t ) ;
162- } ) ;
163-
164- builder . RegisterType < TransactionRequestHandler > ( ) . As < IRequestHandler < ProcessLogonTransactionRequest , ProcessLogonTransactionResponse > > ( ) . SingleInstance ( ) ;
165- builder . RegisterType < TransactionRequestHandler > ( ) . As < IRequestHandler < ProcessSaleTransactionRequest , ProcessSaleTransactionResponse > > ( ) . SingleInstance ( ) ;
157+ services . AddTransient < ServiceFactory > ( context =>
158+ {
159+ return t => context . GetService ( t ) ;
160+ } ) ;
161+
162+ services . AddSingleton < IRequestHandler < ProcessLogonTransactionRequest , ProcessLogonTransactionResponse > , TransactionRequestHandler > ( ) ;
163+ services . AddSingleton < IRequestHandler < ProcessSaleTransactionRequest , ProcessSaleTransactionResponse > , TransactionRequestHandler > ( ) ;
164+
165+ services . AddTransient < Func < String , IOperatorProxy > > ( context => ( operatorIdentifier ) =>
166+ {
167+ SafaricomConfiguration configuration = context . GetRequiredService < SafaricomConfiguration > ( ) ;
168+ HttpClient client = context . GetRequiredService < HttpClient > ( ) ;
169+ return new SafaricomPinlessProxy ( configuration , client ) ;
170+ } ) ;
166171 }
167172
173+
174+
168175 private void ConfigureMiddlewareServices ( IServiceCollection services )
169176 {
170177 services . AddApiVersioning (
0 commit comments