October 2009 - Posts

Thanks to a patch submission by Hakan Forss the Object Hydrator Fluent Interface is now type safe, with all the magic strings removed. The standard inferences are still there so you could do most of your generation without ever using the advanced methods. 

The new syntax for the example in my last post looks like this:

            string defaultValue = "Testing123";

            Hydrator<SimpleCustomer> hydrator = new Hydrator<SimpleCustomer>()

                .With(x => x.Description, defaultValue);

            SimpleCustomer customer = hydrator.GetSingle();

For the second example where you wanted to override the Company name generation, you actually have two choices:

            Hydrator<SimpleCustomer> hydrator = new Hydrator<SimpleCustomer>()

            .WithLastName(x => x.Company);

            SimpleCustomer customer = hydrator.GetSingle();

 

            Hydrator<SimpleCustomer> hydrator2 = new Hydrator<SimpleCustomer>()

            .With(x => x.Company, new FirstNameGenerator());

            SimpleCustomer customer2 = hydrator.GetSingle();

Just kind of depends on what your style is...both work the same.

More to come as we creep on on a release.  Feel free to check this version (.5) out at  http://objecthydrator.codeplex.com
*fixed url

 

Ryan

 

 

 

Posted by ryansjedi | 2 comment(s)
Filed under: , ,

Since last I posted, I've received an awesome implementation of a fluent interface for Object Hydrator from Scott Monnig.  We've ditched the Attributes and mapping scenarios in favor of some convention and  a fluent interface.

So as before this will get you a single customer:

Hydrator<SimpleCustomer> hydrator = new Hydrator<SimpleCustomer>();

SimpleCustomer customer = hydrator.GetSingle();

The difference here is that SimpleCustomer looks slimmer like this:

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Company { get; set; }

        public string Description { get; set; }

        public int Locations { get; set; }

        public DateTime IncorporatedOn { get; set; }

        public Double Revenue { get; set; }

By convention FirstName, fname etc...will use the FirstNameGenerator...and so on.  If there is no infered generator, it will pick one by type.

 If you want to override a value, you do it like this:

            string defaultValue = "Testing123";

 

            Hydrator<SimpleCustomer> hydrator = new Hydrator<SimpleCustomer>()

                .WithDefault("Description", defaultValue);

Easy huh?

What if you wanted to override the Company name with a FirstNameGenerator value for some wacky reason?  Piece of cake...

            Hydrator<SimpleCustomer> hydrator = new Hydrator<SimpleCustomer>()

            .FromGenerator("Company", new FirstNameGenerator());

            SimpleCustomer customer = hydrator.GetSingle();

Aggregate roots are still being worked on and are in this code they require a little deeper info, but check out the source if you are curious where we're going with those.

Please check out the source at http://objecthydrator.codeplex.com and peruse the tests to see more examples.  I'll be doing a deeper write up as we make that first .1 release and will include the source. 

Thanks a ton to Scott and as always feel free to let me know what you think.

Posted by ryansjedi | 1 comment(s)
Filed under: , ,
More Posts