Extending Data Access BLock

Topics: Building and extending application blocks
Jan 20, 2007 at 7:52 AM
I want to extend the data access block. I have to execute some events and functions before/after the execution of Data access functions like iwant to run pre save and post save events.

I want to do his by extending the Data access black
I hve extended the database class like





namespace ExtendedEnterpriseLibrary.Data
{
public class Database //: Microsoft.Practices.EnterpriseLibrary.Data.Database
{
public Database()//(string connectionString, System.Data.Common.DbProviderFactory testInstance)
//: base(connectionString, testInstance)
{

}




But when i am using ExtendedEnterpriseLibrary.Data.Database to execute execute reader its giving type error.

Please give instructions how to extend data access Block
Jan 20, 2007 at 7:58 AM
sorry code is

namespace ExtendedEnterpriseLibrary.Data
{
public class Database : Microsoft.Practices.EnterpriseLibrary.Data.Database
{
public Database()(string connectionString, System.Data.Common.DbProviderFactory testInstance)
: base(connectionString, testInstance)
{

}



Jan 22, 2007 at 2:12 PM
You can read more about extending and modifying the Data Access Application Block in the documentation under Data Access Application Block -> Extending and Modifying the Data Access Application Block.

Extending the block would be essentially creating a new Typed Provider, like SqlDatabase, that supports a new database. A new software factory has been added to the current Enterprise Library 3.0 CTP, Application Block Software Factory, to help you with such tasks. Although documentation is not complete as the factory is still in a CTP phase and subject to change, you may want to look into the new factory for creating a new typed provider.

You are proposing to modify the block, which would mean you will have to modify it, recompile it, and support and version it yourself with new versions of Enterprise Library. That can be a lot of work.

However, you can probably pull off pre- and post-save events in your data access layer, which would keep your from having to modify the block:

public class DataService : IDataService
{
private readonly Database _database;

public DataService(Database database)
{
//TODO: check for null...
_database = database;
}

//TODO: Add events...

public void SaveCustomer(Customer customer)
{
// Fire Pre-Save Event...

// Save Customer

// Fire Post-Save Event...
}
}

Much of this will probably be delegated to a base class. I recommend looking at the Data Access Guidance Package which is in the Web Service Software Factory.

If you definitely prefer to modify the block, you are pretty much on your own because there is no documentation for such a task as it varies upon what modifications you need to perform.

Regards,

Dave

________________________

David Hayden
Microsoft MVP C#
http://www.davidhayden.com/