This project has moved. For the latest updates, please go here.

PartCreator, private default constructor

Jun 20, 2010 at 6:21 PM
Edited Jun 20, 2010 at 6:22 PM


for example, we have class:

class Foo
   public Foo(Bar baz) { /* do smth */ }
   private Foo() {}

where Bar may be standart library class. There is problem with PartCreator<Foo>:

PartCreator<Foo> fooCreator;

// blah-blah-blah

var value = fooCreator.CreatePart().ExportedValue; // I can't correctly initialize the object

Is there solution for my problem?

May i use extensions methods like:

public static class FactoryExtensions
  public static PartLifetimeContext<Foo> CreateByParams(this PartCreator<Foo> partCreator, Bar baz)
     return ???? // what should be there?



Jun 21, 2010 at 3:40 PM

Sorry, we don’t support this scenario. ‘Bar’ needs to be available for composition. 



Jun 21, 2010 at 3:48 PM

Hammett is correct that we don't support this scenario but you can always build in an Initialize method to your contract and after you create the new value call value.Initialize(baz) which is about the best you can do right now.

Jun 21, 2010 at 6:26 PM

I'm already use technique proposed by weshaggard, but i thought that better way posibly exists

Thanks for responses! :)