P
plaztik via DotNetMonster.com
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!
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!