Create Object using ObjectBuilder
Posted
by
dhinesh
on Stack Overflow
See other posts from Stack Overflow
or by dhinesh
Published on 2010-12-21T04:51:14Z
Indexed on
2010/12/21
5:00 UTC
Read the original article
Hit count: 97
c#
Want to create objects using ObjectBuilder or ObjectBuilder2.
I do not want to use StructureMap
I was able to create the object having parameterless constructor using the code mentioned below.
public class ObjectFactory : BuilderBase<BuilderStage>
{
public static T BuildUp<T>()
{
var builder = new Builder();
var locator = new Locator { { typeof(ILifetimeContainer), new LifetimeContainer() } };
var buildUp = builder.BuildUp<T>(locator, null, null);
return buildUp;
}
for creating object of customer you just call
ObjectFactory.BuildUp<Customer>
However this creates object of class which has no parameters, however I need to create object which are having constructor with parameters.
© Stack Overflow or respective owner