views:

220

answers:

1

I have been building web sites with ASP.NET for a while now. At first I avoided learning the intricacies of the ASP.NET Provider Model. Instead I used the canned providers where necessary, and leaned heavily on Dependency Injection frameworks for all my other needs.

Recently however, I have been writing pluggable components for ASP.NET and of course writing lots of custom provider based solutions in order to make that happen. It has become quickly apparent to me however, that a lot of initialization code is being duplicated, which is a bad thing.

So...

  1. Are there any best practices that have emerged on how to avoid the configuration spaghetti code?
  2. Have you built, or have any examples (base/helper classes, custom attributes, reflection) to share of abstracting the basic initialization code out so building custom providers is easier?

NOTE:

Please do not try and send me to the Provider Toolkit site. I have already exhausted that resource, which is why I am turning to the SO Community :)

A: 

I just did a rough implementation of rather basic implementation of the membership and role providers, and I don't have any code duplication at all!

I have divided everything into three projects (plus tests):

  • Application - asp.net mvc app. models, controllers etc.
  • Infrastructure - IoC and Interfaces
  • Infrastructure.Web - Providers

The model for User and Role implement interfaces from Infrastructure and those classes get registered to the IoC on application startup. The providers then asks the IoC to resolve the classes and does it's thing. This way I can add things to the model and user interface yet using the same providers. The one problem I've noticed, is that the web being launched by the "ASP.NET Configuration"-button can't use the providers, as the setup is being done in Application_Start and the "ASP.NET Configuration" is another web. I don't see this as a problem though.

svinto
I am specifically trying to build pluggable components that can be dropped into any ASP.Net project. I would LOVE to use an IoC, but that would rule out the ability for a single DLL that can be dropped into a project and work.
Josh
Include a mini IoC in your component, have the app register a factory that implements a interface in your component, and exposes methods to build the respective classes.
svinto