This project is read-only.

Factory Methods

Jan 9, 2011 at 10:07 AM

Hi Guys,

How difficult would it be to introduce factory methods, or possibly closures for constructing types. i have various classes with protected default constructors and i want to keep it that way. 

was digging around in the code last night trying to understand it... it uses Activator.CreateInstance, perhaps if we could register a func to provide that instance.

            x.Include<Employer>().Using(x => new Employer("Name"))

                .Setup(c => c.HeadOfficeAddress).Use<AddressLine1Source>();

in an example i have i'd like the constructor to be able to use a datasource too... which kind of makes it a bit different. 

here we could just chain datasource onto the construct method which would then just pass those .Next() values along to the CreateInstance...


                .Setup(c => c.HeadOfficeAddress).Use<AddressLine1Source>();

any ideas??

Jan 9, 2011 at 11:20 AM

Can easily do something like that, I'm fairly sure I've already written code to do constructor arguments - factory methods/closures are just an extension of that. I'll add it to the do-do list

Jan 9, 2011 at 11:28 AM