Posts

ASP MVC CheckListBox

I needed to present the user with a list of objects from which they could select multiple items.  There is a MultiSelectList class in ASP MVC so I looked into how to use that.  It would seem that to use this class we need to use Html.ListBox.  I think this is a poor choice because it requires the user to hold down the Control key to select additional options, and it is too easy to deselect all of your values accidentally by clicking the control accidentally without the Control key held down. What I really wanted was something like a CheckListBox, a list of items with a check box next to them, so that’s what I have implemented.  Here is an example of how to set up the view data for my CheckListBox extension. public ActionResult Index() { var availableItems = new List < MyItem > (); availableItems.Add( new MyItem( " A " , " One " )); availableItems.Add( new MyItem( " B " , " Two " )); availableItems.Add( new MyIt

Unity.BuildUp–Ambiguous constructor

Sometimes you have no control over the instantiation of your classes and therefore cannot use Unity. For this reason the BuildUp method was added to Unity in order to either call the method marked with [InjectionMethod] or to set all properties marked with [Dependency].  Unfortunately in the latest build this is broken.  For some reason BuildUp searches for a suitable constructor even though the instance has already been created.  In my case I have two constructors both with only 1 parameter so I get an ambiguous constructor exception. So, I created this helper method to call the InjectionMethod on the instance… public static class UnityContainerHelper { public static void CallInjectionMethod( this IUnityContainer unityContainer, object instance, params ResolverOverride[] overrides) { if (instance == null ) throw new ArgumentNullException( " Instance " ); var injectionMethodInfo = instance.GetType().GetMethods().Where(x =&

ASP MVC encoding route values

I’ve recently been using ASP MVC 2 to develop a business application.  As you may already know the ASP MVC routing system works with URLs which look like this http://localhost/Client/Details/IBM In standard ASPX apps the URL would look more like this http://localhost/Client/Details.aspx?code=IBM The first URL obviously looks much nicer than the 2nd, however it comes at a cost.  What if the “code” of your object is something like “N/A” for “Not applicable”?  You end up with a URL that looks like this http://localhost/AbsenceCode/Details/N/A What we really need is to have ASP MVC encode the value “N/A” as “N%2FA”.  The problem is that even if it did do this then by the time ASP MVC receives the value it has already been decoded, so we get a “400 bad request” error.  This is a real pain, because in business we can’t really tell a customer “You can only use characters A to Z, 0 to 9, underscore and minus in your codes” because they will tell you that they have used the code N/A

ECO and distributed transactions

My current app is a website, each client gets their own unique database in order to help prevent possible data access from other clients (and meet various legal requirements too.)  One of the features of this application is that there is some core data (such as countries/currencies) which is maintained on behalf of the client.  This data will be identical for all clients, and only maintained by a system administrator. Obviously expecting the admin to log into each client to perform updates is unreasonable, so I have structured my app so that there is a separate Admin website which updates a master database and propagates the changes to all of the clients. When the master website does an update it performs it within an IUnitOfWork, and then tells the same update command to execute for each client database too.  If any of these updates fail for whatever reason then the whole thing needs to be cancelled whether one of the child databases updated or not. using (var distributedTransac

Tightly coupling generic types

Update : Instead of decorating responses with IResponseFor<T> I now instead decorate the command/query with IExpectResponse<T> - Each command/query should only have one response type, and this way it makes it possible to specify the return type should be something simple like a GUID. My server application works purely on a request/response pattern, like so var query = new GetCustomerQuery(customerUniqueID); var response = AppServer.Execute < GetCustomerQuery , GetCustomerQueryResponse > (query); What I wanted to avoid though was the possibility that the user (me writing the client app) would do something silly like the following code and use the wrong pair combination var query = new GetCustomerQuery(customerUniqueID); var response = AppServer.Execute < GetCustomerQuery , GetEmployeeQueryResponse > (query); Up until now I had the server interface defined like this, so that I can at least ensure the generic parameters are a Query and R

ECO Persistence Mapper per connection

The Enterprise Core Objects Persistence Mapper is a singleton which is used by all EcoSpace instances.  It’s purpose is to load mapping information from the DB when your app starts and to cache it, improving performance. I needed a connection per client, all running within a single application.  This was a problem because once the PMP is created its connection string is tied to a single database.  So I had to come up with a new PersistenceMapperDynamicSharer component.  It is used on the EcoSpace to specify the PMapper type; additionally you can specify a connection string to use. It works by dynamically creating a descendant class of your PersistenceMapperProvider at runtime, one for each connection string. public class PersistenceMapperDynamicSharer : PersistenceMapperSharer { static ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(); static Dictionary < string , PersistenceMapperProvider > MapperProviders = new Dictionary < string , PersistenceMapperPr