posts - 52, comments - 14, trackbacks - 438748

Cached @ 1/5/2009 10:29:40 AM

Control ASP.skins_anothereon001_controls_blogstats_ascx

My Links

News

Archives

Post Categories

Blogs

Cached @ 1/5/2009 10:29:40 AM

Control ASP.skins_anothereon001_controls_singlecolumn_ascx

VSLive! Day One - Architecting ASP.NET Applications Part 2 - Custom Providers

Custom Providers
The second part of the discussion is opening with a discussion of custom provider development.  This is of great interest to me as my recent work with the Model View Presenter pattern has caused me to research and implement dependency injection for many of the layers of my application.  The current product that I'm working on is implementing the MVP pattern and is using dependency injection to dynamically load a data layer at run time.  There is a need within the product to use a different data access layer assembly for the administrative tools than for the public side of the application.  The murky details behind this decision (which I shall leave aside) are to do with the deployment environment and maintenance cycles of the applications going forward.  There are a few mechanisms for achieving this dynamic load, however I've yet to find conclusive evidence that one method is preferable.

The idea behind dependency injection is improve the following fairly typical line of code:
MyClass myClass = new MyClass();

One potential drawback in this line is that the physical class MyClass has been hard-coded as the only implementation that can exist for myClass.  If MyClass implements an interface IMyClass then it might be desirable in the code to switch out the implementation of the interface IMyClass that is being used.  The example du jour is switching out an MS SQL data access library for an Oracle data access library.  In that example, both implement the same interface but the application wishes to decide which library to use at runtime via a configuration setting.  This is a common problem in applications that wish to implement several version of a library than perform very similar but ultimately different tasks.  The provider model is based around this need.

The suggested methodology presented in this talk is to use:
Type myType = Type.GetType("MyNamespace.MyClassName");
IMyClass myClass = System.Activator.CreateInstance(myType);

The theory here is that Type.GetType returns an object that describes the type to be created.  The System.Activator.CreateInstance line creates a concrete instance of the requested class except by this mechanism the class has been created using a string name versus a hard-coded class name.  This methodology works for classes that exist within the same assembly, however will not work for classes that exist outside of this assembly.  There is an extension to this will work for classes outside of this assembly.

Dynamically Loading Assemblies
In order to extend this methodology to work for classes that are in other assemblies, there is a need to first load that assembly.  This is achieved via the following methodology:
Assembly asm = Assembly.LoadFile(MyAssemblyFileName);
IMyClass myClass = asm.CreateInstance(MyClassName);

The basic change here is that now the concrete class instance is created from the assembly reference versus System.Activator.  This allows the dyanamically loaded class to reside in a separate assembly.  Now we have the ability to specify which data access layer library is being used within the application at run-time.  All calls within the application are made against the IMyClass interface, but the implementations now differ based upon the physical data access library that is loaded at run-time.

Interface Isolation
Finally, interfaces are isolated into a separate assembly from either (any) of the concrete implementations of that interface.  The reason for this is that we do not want to require a reference from the main application to either of the implementations of the interface.  Such a reference would defeat the purpose of the exercise as it would again tie the application directly to a particular implementation.  Instead the main application references only the assembly that contains the interface.  Now any implementation of that interface can be used from within the main application by dynamically instantiating the implementation using the mechanism above.

Print | posted on Tuesday, October 16, 2007 10:14 AM | Filed Under [ ASP.NET ]

Feedback

Gravatar

# Phentermine cheap.

Cheap phentermine. Guaranteed lowest price cheap phentermine online. Cheap phentermine online.
11/1/2007 8:23 AM | Buy cheap phentermine online.
Gravatar

# Order phentermine phentermine online.

Order phentermine from uk.
11/7/2007 3:46 AM | Order phentermine uk.
Gravatar

# Online phentermine cod.

Buy phentermine no prescription cod. Cheap phentermine cod. Phentermine cod.
11/7/2007 9:51 AM | Phentermine cod.
Gravatar

# Phentermine.

Discount phentermine. Cheap phentermine. Phentermine diet pills. Phentermine. Phentermine cheap. Herbal phentermine.
3/17/2008 10:20 AM | Phentermine.
Gravatar

# febnfmei

febnfmei
3/18/2008 11:34 PM | febnfmei
Gravatar

# buy ambien online

buy ambien online
3/23/2008 12:43 PM | buy ambien online
Gravatar

# purchase soma

purchase soma
3/23/2008 12:44 PM | purchase soma
Gravatar

# generic vicodin

generic vicodin
3/23/2008 2:40 PM | generic vicodin
Gravatar

# mzcxbhfp

mzcxbhfp
3/23/2008 10:18 PM | mzcxbhfp
Gravatar

# generic viagra online

generic viagra online
3/24/2008 3:15 AM | generic viagra online
Gravatar

# buy tramadol online

buy tramadol online
3/24/2008 3:15 AM | buy tramadol online
Gravatar

# hnefobbl

hnefobbl
3/24/2008 11:59 AM | hnefobbl
Gravatar

# vttuuwwx

vttuuwwx
3/24/2008 12:00 PM | vttuuwwx
Gravatar

# wtcfgfro

wtcfgfro
3/25/2008 12:48 AM | wtcfgfro
Gravatar

# zmxgozvn

zmxgozvn
3/25/2008 12:48 AM | zmxgozvn
Gravatar

# aatmioca

aatmioca
3/25/2008 12:48 AM | aatmioca
Gravatar

# generic xanax

generic xanax
3/25/2008 5:46 PM | generic xanax
Gravatar

# testosterone

testosterone
3/25/2008 6:57 PM | testosterone
Gravatar

# buy viagra

buy viagra
3/25/2008 6:58 PM | buy viagra
Gravatar

# pkxcwgqz

pkxcwgqz
3/26/2008 2:46 AM | pkxcwgqz
Gravatar

# qxpjqpii

qxpjqpii
3/26/2008 2:46 AM | qxpjqpii
Gravatar

# hgvuclzx

hgvuclzx
3/26/2008 2:46 AM | hgvuclzx
Gravatar

# usywdnuh

usywdnuh
3/26/2008 2:46 AM | usywdnuh
Gravatar

# paroxetine

paroxetine
3/26/2008 7:51 AM | paroxetine
Gravatar

# purchase valium

purchase valium
3/26/2008 9:08 AM | purchase valium
Gravatar

# atorvastatin

atorvastatin
3/26/2008 9:08 AM | atorvastatin
Gravatar

# cheap alprazolam

cheap alprazolam
3/26/2008 10:18 AM | cheap alprazolam
Gravatar

# order tramadol

order tramadol
3/26/2008 10:18 AM | order tramadol
Gravatar

# buy ultram online

buy ultram online
3/26/2008 10:19 AM | buy ultram online
Gravatar

# sumatriptan

sumatriptan
3/26/2008 11:42 PM | sumatriptan
Gravatar

# prinivil

prinivil
3/26/2008 11:43 PM | prinivil
Gravatar

# rqkszipt

rqkszipt
3/27/2008 7:23 AM | rqkszipt
Gravatar

# soma

soma
3/28/2008 12:03 AM | soma
Gravatar

# vcdcydkd

vcdcydkd
3/28/2008 7:18 AM | vcdcydkd
Gravatar

# pwxgsfpt

pwxgsfpt
3/28/2008 7:18 AM | pwxgsfpt
Gravatar

# buy valium

buy valium
3/30/2008 12:35 AM | buy valium
Gravatar

# Ultram tramadol.

Ultram. Ultram er. Ultram tramadol. Ultram ortho mcneil.
4/4/2008 4:39 PM | Ultram.
Gravatar

# No prescription phentermine hcl 37.5mg.

Phentermine 37 5mg.
4/6/2008 1:55 AM | Phentermine 37 5mg.
Gravatar

# Generic phentermine.

Generic phentermine.
Gravatar

# Fioricet information from drugs com.

Webresults fioricet. Fioricet and blood work.
4/15/2008 2:02 PM | Fioricet.
Gravatar

# Fioricet plain pill.

Fioricet cod.
4/16/2008 3:23 PM | Fioricet.
Gravatar

# Order xanax online.

2mg xanax order. Pharmacy order generic xanax. Order xanax with prescription. Order xanax. Xanax mail order. Order prescriptions generic xanax. Order xanax overnight.
4/22/2008 10:14 AM | Order xanax online.
Gravatar

# Boobs.

Wobbling bouncing boobs. Boobs. Big natural boobs.
6/19/2008 5:59 AM | Boobs.
Gravatar

# Incest sex stories.

Incest sex free stories. Incest sex photos. Incest sex stories. Incest sex.
6/19/2008 7:39 PM | Incest sex stories.
Gravatar

# Animal porn.

Animal porn.
7/1/2008 6:06 PM | Animal porn.
Comments have been closed on this topic.

Powered by: