Value of architecture
If I have to tell what is the main property of a good architecture, I surely will answer that a good architecture centralize common operations and make simple to extend the application.
Here is a typical example. I have a WCF services called from external clients, but I use the same service inside my organization. I created a little WPF project that needs to use services functions, but since this program is run internally, I do not want it to pass in the WCF stack, but I simply want to use concrete services classes that access the database.
The solution is really simple, here it is:
|
|
AutoscanComponent is used by a custom Castle facility, and is used to automatically register a component. For services I’m sure that there is always only an instance registered for each interface, so I can simply configure castle to use the autoscan facility, and when the code declare a dependency to IKeywordService, Castle resolve it with the concrete class instead of the WCF Proxy.
But this is not enough, I begin to notice that the program is slow, and after a simple inspection I see that there are too many calls to the database. The problem is that the user interact with a WPF UI and there are too many call to the database because the service interfaces are thought for a different usage pattern. This problem could be easily resolved with caching, so I create a simple interceptor.
|
|
This component is really simple, It builds a string key that represent the cache composing service name + method name + parameterlist, so I’m sure that I cache only calls with the same parameters call. Then I simply use entlib caching application block to store data in cache. Now I simply need to configure this interceptor in config file.
|
|
Next I need to instruct my facility to add this interceptor to all autoregistered components
|
|
With this configuration I’m sure that each service is intercepted by the cache component, cache duration is 5 minutes, and the application gains a tremendous speed increase.
This is possible because the architecture extensively use IoC to resolve services and components, and is simple to add features with AOP.
alk.