My understanding of the flow of events with an ASP.NET Web API Castle Windsorized app that uses Models, Repositories, and Controllers:
0) The client calls a REST method via a URI such as:
http://localhost:28642/api/platypi/Count
1) Castle Windsor's routing engine maps intercepts that incoming call, sending the registered concrete class that implements the interface platypiController has as an arg in its constructor.
2) That constructor determines which of its methods is to be called (what corresponds to "Count" in this case).
3) That Controller method calls a corresponding method on the Repository.
4) The code is run, the data gathered and returned, and the user thinks it's all so easy (one extreme viewpoint) or magical (another, slightly less extreme, viewpoint).
I've created a pair of projects that utilize this and it so far works just dandy. We have several instances of databases for different users (DB1 for a particular set of customers, DB2 for another, etc.) The tables are almost but not quite identical (not guaranteed to remain such), and the queries against those tables are similar.
My conundrum/challenge is how or where to intercept the routing to go this way or that based on which "class" of user is calling.
I'm thinking that I need N Repositories implementing each interface, such as:
interface FooBar
class PhooBar : FooBar // targets DB#1
class PhooeyBar : FooBar // targets DB#2
class PoohBear : FooBar // targets DB#3
But then, how do I tell Castle Windsor or Web API which concrete class/Repository I want?
At any given time, there will be requests coming into the Web API / Castle Windsor app from clients who need to be served DB#1 data, other clients who need DB#2 data, and yet users who need DB#3 data.
Is this something that's accomplished in the URI, such as:
http://localhost:28642/api/platypi/Count/1
(where the appended number indicates which DB to use)
?
or:
http://localhost:28642/api/platypi/Count/PhooBar
or...???
In many cases, the ONLY thing that will have to change between one Repository class and another is the connection string in the constructor. Specifically, this:
@"Provider=Microsoft.ACE.OLEDB.12.0;User ID=qypav1;Password=QqPamPoamMSET;Data Source=C:CatcherNTheRyeDATAOMDDAT03.MDB;Jet OLEDB:System database=C:Catch22Datarip.mdw"))
...will need to be:
@"Provider=Microsoft.ACE.OLEDB.12.0;User ID=qypav1;Password=QqPamPoamMSET;Data Source=C:CatcherNTheRyeDATAOMDDAT01.MDB;Jet OLEDB:System database=C:Catch22Datarip.mdw"))
(OMDDAT03 becomes OMDDAT01)
See Question&Answers more detail:
os