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…
DinnerNow for Microsoft Visual Studio Beta 2
August 9, 2007
Yes, we're back with another release! You might noticed that people is talking about Orcas Beta 2, but you will be wondering “How can I see all the Microsoft Visual Studio 2008 features running and working in the same place?”. Here's your answer DinnerNow is back!
We built this version of DinnerNow using Microsoft Visual Studio 2008. We've modified the code to be Microsoft Visual Studio 2008 compliant.
Highlights of the drop
- Official Windows CardSpace Icons
- Revised WPF kiosk application that can be loaded in the Visual Studio designer for WPF
- Integration with the mobile application
- Migrated Service Portfolio projects to new templates (WCF Service Library & Workflow Service Library)
- Improved the REST/POX/RSS support using the new WCF 3.5 programming model.
So what? Get the bits now!
thanks,
~johnny
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
Hungry for training?… Ok, we’ve got your solution!
August 1, 2007
These days lot of things are coming around, as I mentioned on the DinnerNow.net posts, lot of technologies were made available. Some of them in beta phase , and some as final releases.
I know, you’ll probably say: “Ok, I’ve downloaded DinnerNow.net, installed it, and I’ve seen those technologies working together but now what?”. Ok, here is what can you do: I’m proud to announce (as James Conard did in his weblog) that Windows Server 2008 Developer Training Kit (Beta 3) is now public & available.

What I will find if I download the package?
The kit contains presentations used by Developer & Platform Evangelism (DPE) on their early adoption program for ISV (a.k.a Touchdown). It contains presentations on 15 different topics going from IIS7 to .Net 3.0 including stuff like Virtualization and High Performance Computing. It also includes 7 hands on labs, where Southworks helped the DPE team on the development. Check out Gabriel’s blog to read more about the labs.
What should I do now?
C’mon, the answer is easy… Get the bits now! And don’t forget to check James’ post about it!
Also I want to congratulate to the guys who contribute to this amazing package, like: Jason Olson, David Aiken, Matt Winkler, Nigel Watling, Brett Hill, Volker Will, and Justin Smith.
That’s all folks… and stay tuned.
thanks,
~johnny



