dedicated to write powerful yet elegant software by using minimum code and maximizing the benefits for all our clients.

"The Managed Extensibility Framework (MEF) simplifies the creation of extensible applications. MEF offers discovery and composition abilities that you can leverage to load application extensions." - (mef.codeplex.com)

"The common service locator library contains a shared interface for service location which application and framework developers can reference"  - (commonservicelocator.codeplex.com)

Wow!

How to get them both working together, is as below.

NOTE: I am assuming that the reader is aware of Dependency Injection pattern & the Common Service Locator.

The Steps:

  1. Download the CommonServiceLocator_MefAdapter.4.0.zip file & extract the MefServiceLocator class written by Glen Block
  2. Create a new ASP.Net MVC 2.0 Web Application Project
  3. Include the MefServiceLocator class into this project
  4. Open the Global.asax.cs file
  5. Make the following code change in the Application_Start event:
    protected void Application_Start(){
    RegisterDIContainer();
    AreaRegisteration.RegisterAllAreas();
    RegisterRoutes(RouteTable.Routes);
    }
  6. Write the RegisterDIContainer method as:
    protected void RegisterDIContainer(){
    var catalog = new AggregateCatalog(
    new AssemblyCatalog(Assembly.GetExecutingAssembly()),
    new DirectoryCatalog(Server.MapPath("~/Plugins"))
    );
    var composition = new CompositionContainer(catalog);
    composition.ComposeParts(this);
    var mef = new MefServiceLocator(composition);
    ServiceLocator.SetLocatorProvider(() => mef);
    }
  7. With this in place, you are now good to do:
    var controllers = ServiceLocator.Current.GetAllInstances<IController>();

Code on...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Category: ASP.Net MVC | C# | Design Patterns | Web Development

WebsiteManager v1.0 Released! by Sunny 19/Jul/2009 00:19:00

Ladies & Gentlemen, presenting my first open-source application called WebsiteManager - finally released & ready for you good folks to use!

This version (v1.0) provides a UI to manage the ASP.Net Memberships & roles via a web application using ASP.Net MVC 3.5 (although you could use it on ASP.Net MVC 2.0 also)

I have a couple of useful ideas which I plan to implement in this application during the course of the new few releases.

So hang tight :)

Please feel free to download the latest bits from CodePlex, use it as you see fit.

I would truly appreciate some feedback on this effort & open to any new ideas you would like to see put into the future releases.

Again - CodePlex is the place for all this information. Have fun!

Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Category: ASP.Net MVC | General | Tools

Typically, new developers to ASP.Net MVC get stumped with having to deal with one important fact: Page.ResolveUrl(...); is missing!!!

Don't worry or fret - the new way of doing this is:Url.Content(...);

Some sample usage is as below:

Resolving images:

<img src="<%= Url.Content("~/content/images/myImage.gif") %>" alt="My image" title="My image" />

Resolving JavaScript files:

<script language="javascript" type="text\javascript" src="<%= Url.Content("~/scripts/myscript.js") %>"></script>

Simple as that.

When you refer stylesheet files in your *.Master page, this link is directly reference without needing to use the Url helper as shown above.

So, you can continue refering stylesheet files like:

<link rel="stylesheet" type="text\css" media="screen" href="../content/site.css" />

The MVC framework will resolve the path correctly at run-time.

Hmm.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Category: Development | ASP.Net MVC

Referencing external files in MVC Views by 13/Jun/2009 09:08:42

Resolving JS/CSS/Img paths in MVC Views

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Category: Web Development | ASP.Net MVC