I am open to other IoC containers, such as NInject and StructureMap if they are much cleaner than this. I hear that StructureMap just introduced "containers" that may simplify this , perhaps?
As the title says, is there a better way? This seems like a lot of code, just to register an object that requires a factory to create it.
// The process to register an object, with a factory method
var cfg = new MutableConfiguration(p.Name);
cfg.Attributes["factoryId"] = p.TypeFactory.Name;
cfg.Attributes["factoryCreate"] = "Create";
var model = _container.Kernel.ComponentModelBuilder.BuildModel(
p.Name, p.TypeService, p.Type, null);
model.LifestyleType = LifestyleType.Pooled;
model.Configuration = cfg;
_container.Kernel.AddCustomComponent(model);
Versas the "non-factory" way of adding a component:
// registering a component with no factory method
_container.AddComponentLifeStyle(
p.Name, p.TypeService, p.Type, LifestyleType.Singleton);
The first seems overly complex.
Thanks in advance!