Enterprise Library - Indirect/Inherited Configuration??

Discussion in 'ASP .Net' started by plaztik via DotNetMonster.com, May 6, 2005.

  1. Hello,

    My company creates many similar web applications for clients. I was
    assigned the task of creating a versionable engine for producing these web
    applications easily and protecting our code.

    I am creating an assembly that functions as the guts of the web
    applications we are producing. This way, all our code is contained within a
    distributable DLL, so the only code clients see is that which is specific
    to their business processes.

    I would like to use EntLib in my DLL, but I don't want configure and
    compile a custom version of our DLL for each client. (That kind-of defeats
    the purpose, right?)

    So, my question is:

    How can I get my DLL to grab the EntLib configuration settings from the web
    app's web.config instead of customizing my DLL for each client directly?

    Here is an overview of the code structure:

    MyDLL:

    // MyEngine is the facade from which all processes take place
    public class MyEngine
    {
    private CustomerManager _customerManager;

    public CustomerManager CustomerManager
    {
    get { return _customerManager; }
    }

    public MyEngine()
    {
    _customerManager = new CustomerManager();
    }
    }

    public class CustomerManager
    {
    private CustomerDB _customerDB;

    public CustomerManager()
    {
    _customerDB = new CustomerDB();
    }

    public void AddCustomer(CustomerEntity customer)
    {
    if (ValidCustomer(customer))
    {
    _customerDB.Insert(customer);
    }
    }

    public bool ValidCustomer(CustomerEntity customer)
    {
    return true;
    }
    }

    public class CustomerDB
    {
    public CustomerDB()
    {}

    public void Insert(CustomerEntity customer)
    {
    // Ent Lib data needs database configuration...
    Database db = DatabaseFactory.CreateDatabase("?????????");
    db.ExecuteNonQuery(db.GetStoredProcCommandWrapper
    ("InsertCustomer",customer.ParamArray()));
    }
    }

    public abstract class CustomerEntity
    {
    public abstract object[] ParamArray();
    }

    MyWebApp:

    public class Customer : CustomerEntity
    {
    private int _id;
    private string _name;

    public int ID { get { return _id;} set { _id = value; } }
    public string Name { get { return _name;} set { _name = value; } }

    Customer() {}

    public override object[] ParamArray()
    {
    object[] myParamArray = new object[2];
    myParamArray[0] = _id;
    myParamArray[1] = _name;
    return myParamArray;
    }
    }

    public class WebForm1 : System.Web.UI.Page
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    MyEngine theEngine = new MyEngine();
    Customer theCustomer = new Customer();
    theCustomer.ID = 1;
    theCustomer.Name = "Bob";
    theEngine.CustomerManager.AddCustomer(theCustomer);
    }
    }

    The way I have this set up, the entities are configured in the web apps and
    passed into my DLL via the inheritance with the abstract Entity classes.
    This avoided the need for configuring the DLL separately, but now I am
    stuck at getting the EntLib configured too.

    Input welcome and appreciated!

    Thanks!

    --
    Message posted via http://www.dotnetmonster.com
    plaztik via DotNetMonster.com, May 6, 2005
    #1
    1. Advertising

  2. plaztik via DotNetMonster.com

    Scott Allen Guest

    Hi plaztik:

    Pardon me if I don't understand the questions.

    Web.config is the configuration file for the entire application,
    including all the assemblies / dlls loaded into the app. If your class
    library asks the framework for an application setting, the answer will
    come back from web.config.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Fri, 06 May 2005 00:40:51 GMT, "plaztik via DotNetMonster.com"
    <> wrote:

    >Hello,
    >
    >My company creates many similar web applications for clients. I was
    >assigned the task of creating a versionable engine for producing these web
    >applications easily and protecting our code.
    >
    >I am creating an assembly that functions as the guts of the web
    >applications we are producing. This way, all our code is contained within a
    >distributable DLL, so the only code clients see is that which is specific
    >to their business processes.
    >
    >I would like to use EntLib in my DLL, but I don't want configure and
    >compile a custom version of our DLL for each client. (That kind-of defeats
    >the purpose, right?)
    >
    >So, my question is:
    >
    >How can I get my DLL to grab the EntLib configuration settings from the web
    >app's web.config instead of customizing my DLL for each client directly?
    >
    >Here is an overview of the code structure:
    >
    >MyDLL:
    >
    >// MyEngine is the facade from which all processes take place
    > public class MyEngine
    > {
    > private CustomerManager _customerManager;
    >
    > public CustomerManager CustomerManager
    > {
    > get { return _customerManager; }
    > }
    >
    > public MyEngine()
    > {
    > _customerManager = new CustomerManager();
    > }
    > }
    >
    > public class CustomerManager
    > {
    > private CustomerDB _customerDB;
    >
    > public CustomerManager()
    > {
    > _customerDB = new CustomerDB();
    > }
    >
    > public void AddCustomer(CustomerEntity customer)
    > {
    > if (ValidCustomer(customer))
    > {
    > _customerDB.Insert(customer);
    > }
    > }
    >
    > public bool ValidCustomer(CustomerEntity customer)
    > {
    > return true;
    > }
    > }
    >
    > public class CustomerDB
    > {
    > public CustomerDB()
    > {}
    >
    > public void Insert(CustomerEntity customer)
    > {
    > // Ent Lib data needs database configuration...
    > Database db = DatabaseFactory.CreateDatabase("?????????");
    > db.ExecuteNonQuery(db.GetStoredProcCommandWrapper
    >("InsertCustomer",customer.ParamArray()));
    > }
    > }
    >
    > public abstract class CustomerEntity
    > {
    > public abstract object[] ParamArray();
    > }
    >
    >MyWebApp:
    >
    > public class Customer : CustomerEntity
    > {
    > private int _id;
    > private string _name;
    >
    > public int ID { get { return _id;} set { _id = value; } }
    > public string Name { get { return _name;} set { _name = value; } }
    >
    > Customer() {}
    >
    > public override object[] ParamArray()
    > {
    > object[] myParamArray = new object[2];
    > myParamArray[0] = _id;
    > myParamArray[1] = _name;
    > return myParamArray;
    > }
    > }
    >
    > public class WebForm1 : System.Web.UI.Page
    > {
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > MyEngine theEngine = new MyEngine();
    > Customer theCustomer = new Customer();
    > theCustomer.ID = 1;
    > theCustomer.Name = "Bob";
    > theEngine.CustomerManager.AddCustomer(theCustomer);
    > }
    > }
    >
    >The way I have this set up, the entities are configured in the web apps and
    >passed into my DLL via the inheritance with the abstract Entity classes.
    >This avoided the need for configuring the DLL separately, but now I am
    >stuck at getting the EntLib configured too.
    >
    >Input welcome and appreciated!
    >
    >Thanks!
    Scott Allen, May 6, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    809
  2. Replies:
    3
    Views:
    551
  3. Replies:
    3
    Views:
    396
    Tom Dyess
    Jan 20, 2005
  4. Jess Chadwick
    Replies:
    1
    Views:
    4,767
    Steven Cheng[MSFT]
    Sep 21, 2006
  5. Rick Mavrovik

    Enterprise Library Configuration setting!

    Rick Mavrovik, Jul 11, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    611
    Michael Nemtsev
    Jul 11, 2007
Loading...

Share This Page