Enterprise Library
Today we will talk about the Enterprise Library (EntLib). I won't cover here that on version X you could that thing this way or that on version Y you would do this way. I'm just going to explain how does it can help us to improve our produtivity and get a better coding experience among the team's developers.
How to deliver a great solution?
When I'm asked of how much we will better when using EntLib I usually say that it'll get better, but how much will depends on your developers. That's right, how many times you give a developer a powerfull tool and the solution produced is so poor that you become shame or how often you produce great softwares that you thought wasn't possible with 'the version' you got? EntLib is a great step ahead to improve the quality and produtivity of a team, but you need to open up your mind to accept the new concepts you'll have to follow, new commands and sometimes new words too!
What's EntLib?
EntLib is a set of classes that were built to avoid that you, developer, have to write the same portion of code everytime to do the same. As usually, I'll start giving the example of Database connection. How many times you needed to do the following:
- Declare connection, command and parameters variables?
- Build or discover the connection string to connect to a database?
- Read appsettings to return the values of a connection string?
- Open a connection?
- Execute some command?
- Get the return of the execution?
As you can see, it's always the samething and you can use EntLib to avoid this kind of repetition.
Data Access Application Block - DAAB
The first EntLib block you might be curious to see is Data Access for sure. This happens because we always need Data Access on our applications and we always need to do the same thing to accomplish the task.
For teams, the benefits of using EntLib are huge! Just for an example, the lead developer can set up all the connections strings, store them on a config file on SourceSafe or any other source control software and then all the team will have access to that configuration.
Think about another great application block, called Exception Handling Application Block (EHAB). You can config EHAB to work with DAAB, handling some data access errors that can occurr and log the errors on a file, Event Viewer or just send an email with the error.
Now, let's show how you can begin your work with EntLib.
First of all, click here and download the May 2007 version of EntLib. After the installation, just run EntLib, you will see something like this:
Everything begins here. Just right click on Enterprise Library Configuration on the left panel, and the choose 'New Application'. Again, you will see something like the follow:
For this small first example and touch with EntLib, again, right click on 'Application Configuration' on the left panel and the choose 'New | Data Access Application Block'. For the DAAB work, we need to set up the connection strings we want, giving them names and properties.
Now, the structure that you will se on the left panel is like this:
Bellow the node 'Connetion Strings' you can add how many connections you want, giving name as well,setting up the way you want and with the provider you need. I'll not show any example of connection string here, but if you have any problem, please tell me.
After setting up the connections string you might be curious to see EntLib in action. Well to do that, you can now save the application you created and close Enterprise Library Configuration. You will start Microsoft Visual Studio, create your solution in the language you want (Visual Basic, C#). If the solution haven't a config file, add one, otherwise, just open up the existing config file. Then through Windows Explorer, locate the file you saved on 'Enterprise Library Configuration' and then copy it's contents to your config file. On web.config, paste it inside configuration tag.
Now the final act, consumig the EntLib. Just do the following:
- Add a reference to 'Enterprise Library Shared Library';
- Add a reference to 'Enterprise Library Data Access Application Block'.
- On your code add the import/using reference to 'Microsoft.Practices.EnterpriseLibrary.Data'
- Then just paste the code below on the desired method:
On the code above "northwind" is the name of the connection string on EntLib config File.
Just run the application and you will se EntLib in action.
Conclusion
EntLib is a great support base to help on creating next level applications. Please use it as much as possible and you will se that you wonder how did you live without it until now!!
For more documentation, please see the official page of EntLib clicking here.
See ya!@!
Chilá