Archive for the ‘Technology’ Category

Asp.net MVC 3 & Membership Provider

Wednesday, August 25th, 2010

It’s easy to have the mvc membership provider working with mvc3.

  1. Install VS 2010 express.
  2. Install MVC3.
  3. Create a MVC3 website.
  4. Publish the site to the hosting company’s server via ftp.
  5. Install the membership provider from http://mvcmembership.codeplex.com/
  6. Copy the necessary assemblies from the sample website to your website. The primary dll is mvcmembership.dll
  7. Run the aspnet_regsql.exe and point the destination to your sql database.
  8. Change the membership provider connection string to point to the sql database.

SQL Performance improvement

Monday, May 3rd, 2010
  1. Make sure there are indexes available.
  2. Not too much denormalization. The joins cause performance problems.
  3. Are triggers causing an insert operation?
  4. Select only the columns needed.

Dependency Injection

Sunday, May 2nd, 2010

The dependency injection is a hype in the unit tests world. Some hate it, some love it. The dependency injection is injecting the dependency in a system where the objects are disconnected with loose coupling and require dependency injection to make the system to work. For example, a data retrieval manager can have a data connection object. Before the data retrieval is created, the connection object is created in it’s constructor. This dependency can be broken, and the connection object can be passed as a dependency. That’s what dependency inject is. Now both the connection and manager can be tested separately. There are few ways this injection can be done – constructor injection, setter injection. The third type of injection is through service locater. The service located is a container that creates the objects. This takes the responsibility out of the client to create the objects.

There are few things that are bad about DI. Too much decoupling is bad. The client has to create all the objects for a simple thing to work. The overhead of service locater using the reflector can’t give you an idea of how much time some methods to execute in reality.

.net Dispose Vs Finalize

Tuesday, April 27th, 2010

The Dispose Finalize pattern is being used to free the resources in .net. In the C++ world, the resource freeing was deterministic. In .net, it is not. The rule of thumb is to use Dispose to free non-managed resources and Finalize to free managed resources. To use Dispose method, the class has to implement the IDisposable interface. The Dispose method needs to be called explicitly. Normally it is done in using statement. The Finalize is defined like a C++ destructor with ~. The Finalize is expensive and run from different threads by the .net. If Dispose is being called to free a resource, make sure there is a suppress call to Finalize to supress further resource freeing.

Threading in .net

Monday, April 26th, 2010

There are two ways to create threads in .net. Using the .net threadpool, a thread can be created and run. They are efficient than manually creating a thread and running. It is expensive creating and destroying threads manually. The threadpool manages the thread switching efficiently. The WCF, web services, asp.net web request are all multi threaded apps running in a .net thread pool. The BackgroundWorker helps to create worker thread and run. It is efficient as ThreadPool – Threadpool calls BackgroundWorker to run tasks. This uses events mechanism to queue up functions.

The synchronization can be achieved with Mutex.Start() and Mutex.Stop() critical section objects. The lock() can also be used to protect an area of operation. When locking is used, it is important to lock objects only – locking primitive data items and the lock will create boxes to handle it. Each item a thread is created for a request, boxing happens, and there is no synchronization.