We’ve finally released the Patterns & Practices Repository Factory. This release contains the source code at the completion of the patterns & practices work on this project. As we said before now the destiny it’s on your hands.
The work done includes:
- Independent of Service Factory tree
- Generic code has been moved into a separate assembly instead of being generated every time
- Generated code has been placed in different folders to keep the underlying goop out of the way
- Interfaces are generated for the repositories, so you can provide multiple implementations of the repository
- Auto-mapping of entity fields and stored proc parameters
- Recipe inputs are stored across runs so you don’t have to reenter everything every time you run
- New, easier to use and understand UI screens
and many other additions…
Requirements
To compile this package, you need:
- Visual Studio 2005
- GAT and GAX July 2007 CTP
The package will also compile and run with the earlier GAX Feburary 2007 CTP.
If you wish to compile and run the unit test projects, you’ll need Visual Studio Team Test, Team Developer, or Team Suite editions.
Compilation and installation
Open the DataAccess Guidance Package.sln file and compile.
The easiest way to install the package is to compile the setup project and run the resulting MSI. The guidance package requires a registry key in order to find various support DLL’s needed at runtime. The MSI will create this key for you.
If you wish to manually register and use the guidance package, this registry key is:
HKEY_LOCAL_MACHINE\Software\Microsoft\patterns & practices\Repository Factory
Create a string value named "EntlibBinaryPath" and point it at a directory that contains the following DLLs:
- Microsoft.Practices.EnterpriseLibrary.Common.dll (available in Entlib 3.1 and included in the Lib folder in the drop)
- Microsoft.Practices.EnterpriseLibrary.Data.dll (available in Entlib 3.1 and included in the Lib folder in the drop)
- Microsoft.Practices.ObjectBuilder.dll (available in Entlib 3.1 and included in the Lib folder in the drop)
- Microsoft.Practices.RecipeFramework.Extensions.dll (Included in the Lib folder in the drop)
- Microsoft.Practices.Repository.dll (compile from source)
- Microsoft.Practices.RepositoryFactory.SchemaDiscovery.dll (compile from source)
-
You can get both (supported release code and/or Msi) go to: http://www.codeplex.com/RepositoryFactory/Release/ProjectReleases.aspx?ReleaseId=7429
thanks,
~johnny
Repository Factory - P&P Development Completed
September 17, 2007
Hi! First of all I want to recognize my fault since the last two weeks I didn’t made my weekly-post. I’ve been very busy completing the remaining stuff from Repository Factory. That mostly includes the rework of the Create Repository recipe.
Now it’s a wizard!
As you might know our core in this factory was the generation of Repositories, Chris figured out that it was too hard to do (as it was designed). So we’ve converted the addition of operations to the repository from an ugly screen to a wizard.
Operation detail
Improved parameter mapping
Summary
I’d like to close this post saying thank you. All the improvements done in this project have been community-driven. As I insisted in all the posts about the Repository Factory, the community managed the course of the actions by prioritizing, voting, providing feedback, and reading these posts. Now it’s our call to action: Wanted- Project coordinator and members. Yes, now you have the opportunity to be a developer for this factory!.
From my side I want to thank the community members like BennyXNO and David Hayden whose continuous feedback help us a lot while doing the factory. I’m really happy to work with Chris Tavares who is a great developer and was a great Project Manager.
thanks,
~johnny
Repository Factory - Week #3
August 28, 2007
As I promised when we launch this project, I’m reporting each week the progress that we’ve accomplished in the past week. This week has been mostly QA and a highly valuable improvement.
Improved wizard reentrancy
Last week we’ve accomplished wizard reentrancy for Create repository recipe, but we had a bug where we’re not persisting the Identity for each operation (when it applies). Now we’ve added the Identity to the recipe state file as depicted below.
Fixed mapping duplication
When you had a stored procedure that uses a parameter and it’s also included on the as ReturnValue it appear twice in the mappings. Now we’ve fixed this by adding the parameter direction on the recipe state file. How now a parameter looks like
<parameter propertyName=”Name” parameterName=”pty_Name” parameterDirection=”6″ />
Enabled recipes to run on IIS hosted project
We’ve done a small fix to the GetConfigurationAction that allows you to run the recipes that uses configuration file on web sites that are not on File-System.
Place generated code on folders by entity
This was the major improvement for this week. Previously when you generated a repository, all the files that comes along with it where added to the root of the Data Access Project. Chris figured out that once we’ve the RepositoryFactory.Create you no longer needed to be aware of those file and generated repository implementation neither. Now this is how your data access project will look like.
This improvement has a couple of benefits:
- If you want to get rid of the generated code and maintain just the interface, now you just have to remove the {EntityName}RepositoryArtifacts folder.
- All the generated code is encapsulated in a single folder, so you don’t have to be aware of how many files and the implementation details since you’re relying on the factory.
- In addition to the RepositoryFactory.Create() this will keep your projects not aware of where the generated files are.
Finally, if you use the generated stuff as showed below, you’ll just have to include a Using to DataAccessProjectNamespace.
using ClassLibrary17; using Microsoft.Practices.Repository; public static class Class1 { public static void Main() { IPersonRepository repository = RepositoryFactory.Create(); } }
This week we’re probably tackling the rework of the UI. We want to make the factory more usable, since we consider the usability as a core part for software factories.
Summary
We finished another week, all the tackled issues were not invented by us, they are community requests. We’re listening to you, please feel free to provide feedback in our community site. We work on the improvements starting with highly ranked ones, you have a chance to influence the course of the project.
thanks,
~johnny
Repository Factory support in EntLib Configuration Tool
August 24, 2007
Reading David Hayden’s blog, I’ve found that he made a plug-in that allows you to manage Repository Factory configuration information in your app.config/web.config file using the Enterprise Library Configuration Tool GUI.
You can read more on the plug-in on his post here.
Stay tuned, another update on Repository Factory is on its way.
thanks,
~johnny
Repository Factory - Week #2
August 20, 2007
Another report of Repository Factory from the trenches. Now we’ve completed the week of work. In addition to what we’ve done last week this is the report of the stuff completed during this second week.
As I told you on previous posts this project is community oriented, you can decide what we should do during next week. How? Enter our community site and keep voting for your favorite issues.
Repository Class improvements
Our previously generated repository used to have the databaseName field on its declaration, that field is no needed since it’s declared on base class (Repository). In addition we’ve updated the Repository class to allow you instantiate a repository using the default database declared on the config file.
public class PersonRepository : Repository, IPersonRepository { // This field has been removed.private string databaseName;public PersonRepository(string databaseName) : base(databaseName) {} // Added c’tor overload that allows you the usage of defaultDatabase // declaration used by Enterprise Library DAAB. public PersonRepository() : base() {} }
Enterprise Library default database configuration, it’s done by adding this line to your config file.
<dataConfiguration defaultDatabase=”myConnectionString” />
In addition to the changes done to the Repository class and T4 template, we’ve modified the RepositoryFactory class allowing you to instantiate a repository without connection name.
public static class RepositoryFactory { // These are the added overloads that allows you // the instantiation of the repository class without // passing the connection string name. public static T Create(); public static object Create(Type repositoryInterface); }
Combining that configuration line and the improvements done this week, now you’re allowed to use the RepositoryFactory in this way
public static void Main(string[] args) { IPersonRepository repository = RepositoryFactory.Create(); }
Configuration issue fixed
We’ve modified the way the recipe edits the configuration file and appends the repository mapping information. More information can be found in the following snippet I took out from the code.
[FILE: SetRepositoryMappingAction.cs]
public override void Execute() { // We’re using XML in this action because there’s a // dll issue with Guidance Package and the target project. // They’re referencing the same assembly but in different // locations and that generates that runtime errors. XmlDocument document = new XmlDocument(); document.Load(configuration.FilePath); EnsureConfigurationSectionDeclarationExists(“repositoryFactory”, Resources.RepositoryFactorySectionDeclaration); XmlNode repositoryFactorySection = GetOrCreateConfigurationSection (“repositoryFactory”); AddRepositoryMappings(repositoryFactorySection, document); document.Save(configuration.FilePath); }
Create Repository wizard reentrancy
One of the most voted issues on our community site was giving the “Create repository recipe” the ability to store the operations and mappings selected the last time you’ve used it to create a repository for a given entity. I’ll show this new improvement with a sample.
The wizard page
On this page you’ve to specify the operations you want to generate in your repository class, the improvement we’ve done allows you to store this information as metadata on a rcpState file.
The generated recipe state file
The recipe state file is an Xml file that stores the information of the operations you’ve chosen to generate the repository. The structure is depicted on the snippet bellow
<repositoryInformation> <repositoryMetadata name=”Person”> <operation operationName=”DeletePerson” hasInputParameters=”True” procedure=”DeletePerson” operationType=”DeleteOne” /> </repositoryMetadata> </repositoryInformation>
Finally the Xml is stored on the solution folder, with the solution name and rcpstate extension.
Documentation
We have added the ///XMLDoc to all of the types existing on the Microsoft.Practices.Repository.
Summary
We finished another week, all the tackled issues were not invented by us, they are community requests. We’re listening to you, please feel free to provide feedback in our community site. We work on the improvements starting with highly ranked ones, you have a chance to influence the course of the project.
Also we’ve dropped our first CTP that you can find as source code release here.
thanks,
~johnny
Repository Factory - Week#1
August 13, 2007
We've completed the first week working on the Repository Factory project. As I mentioned on a previous post, Chris Tavares and I are working on this amazing project.
I'd like to share with you the improvements we've done during this week, and remember that your vote decides the future of the project. Enter codeplex and keep voting, we're tackling most voted stuff.
GAT/GAX July 2007 Support
We have migrated the guidance package to GAT/GAX July 2007 CTP. More about GAT/GAX 2007 migration can be found here.
Service Factory independent
We've removed all the dependencies to Microsoft Patterns & Practices Service Factory, so you can run the package without the necessity of having the Service Factory installed.
Place generic code into its own DLL
As you might recall the formerly Data Access Guidance Package generated a folder called generic on your Data Access Project. The intent of that was having base-classes for the repository assets. But that code was always the same, so we moved that code a new assembly called Microsoft.Practices.Repository. This new assembly contains the generic code, making your DAC projects are smaller, and easy to maintain.
Generate interface for Repository
Let's explain this point with little bit of code. Suppose that we've a presenter class, that uses the repository, and we want to use IoC pattern. Our code should look like this:
public class Presenter { public Presenter(Repository repository) { //TODO: Add some constructor logic here } }
Since we're sticking to the concrete repository implementation, we won't be able to mock the repository implementation, when we want to write a unit test. Ok, you might be thinking that you can easily do Right Click -> Extract Interface, we knew that but better than using the refactoring tools we're doing it for you. Both repository and interface are generated by Repository Factory. e.g.
//The interface generated by RF public interface IMyRepository { void Add(MyEntity entity); } //The concrete class public class Repository : IMyRepository { public void Add(MyEntity entity) { } }
Create factory to retrieve repositories
Based on the previously explained improvement (Generate Interface for Repository), we've created a RepositoryFactory (besides the GP, a class) that you can use on your code to insulate callers from the concrete repository implementation. Based on this you can write code to retrieve the repository by it's interface and then you can change the implementation by modifying the config file.
Usage
public void SomeMethod() { IPersonRepository repository = RepositoryFactory.Create(connectionString); }
On the config file you'll have something like this
<repositoryFactory> <repositories> <add repositoryInterface=”IMyRepository, MyAssembly” repositoryType=”MyRepository, MyAssembly” /> </repositories> </repositoryFactory>
Auto-map entity fields to Stored Procedure parameters
Sometimes you'll have to add an operation to your repository that is more than just a single CRUD operation. Previously when you needed to create this operation you had to map the input/output parameters and return values from to entity fields. Now we've improved this by automating the mapping. It's a little bit smarter than just mapping Name -> sProcName, it performs the mapping ignoring case and removing “pty_” (and other suffixes).
Summary
We finished this first week, all the tackled issues were not invented by us, they are community requests. We're listening to you, please feel free to provide feedback in our community site. We work on the improvements starting with highly ranked ones, you have a chance to influence the course of the project.
We're going to be delivering a CTP version soon! So stay tuned…
thanks,
~johnny
PS. Acknowledgements
I want to thank Paulo who gave my blog the new head-wash, he is a really creative person, don't forget to check out his blog…
Repository Factory kick off!
August 7, 2007
Today Chris Tavares and I started working on the Repository Factory. This is a guidance package that automates creation of entity classes that map to database tables and repository classes to read and write those entity classes. The generated code removes the tedium task of creating a persistence-ignorant domain model.
This package was originally shipped with the Web Service Software Factory as “Data Access Guidance Package”. But we saw that Data Access is a much larger problem space than just services. The source code of the current Guidance Package is available on CodePlex website www.codeplex.com/RepositoryFactory.
On CodePlex web site you’ll find the list of work items we’ve identified and also some community added. If you’ve got a suggestion or want something to be in the Guidance Package, enter our CodePlex site and vote for your favorite work item.
FAQ
Q: Is this another ORM?
A: No, this package is intended to be a light-weight code generator that automates most of the tasks needed to generate a domain model object and persist them to data base.
Q: Does this project has defined scope and a road map?
A: No, although we have a set of planned updates, once they’re competed where going to release the package to the community to drive and develop. Your welcome to participate, for more info visit Contributing Repository Factory
Q: Do I need the Web Service Factory to use this package?
A: No, you’ll be able to generate repositories to whatever type of application you’re building.
Q: Should I wait to your last release to use it?
A: Definitely no, each time we check-in something new it will be related to an issue/feature/enhancement, so you’ll be able to download the code and start using it.
Q: Which is the first thing you’ll get done?
A: We’re currently working on the package independence and isolation from the Web Service Software Factory.Also the factory generates a bunch of generic classes along with the repository, now they’re going to be placed in a separated dll and referenced from the project. The result: a cleaner repository project, and removed the duplication of code when you have more than one repository project.
Stay tuned, at the end of each week I’ll try to post what are the enhancements we’ve done.
thanks,
~johnny





