Howdy, what a creazy stuff! This is going in the direction I want to have. But if I understood your snipped correctly I've to create a concrete factory for each Object type which could be created (with the benefit to support different ctor's), right ?
This is what I want to avoid and use Lambda expressions instead. I've implemented an IOC Container, where you actually could register objects in 3 ways:
1. For Transient object resolving : container.register<Mesh>();
2. For Transient object resolving by contract: container.register<Mesh, IMesh>();
3. For Singleton object resolving : container.register<Mesh>(std::make_shared<Mesh>());
This allowes me to register objects without arguments, which could simple resolved with:
auto mesh = container.resolve<Mesh>().
Now I'm at the point, that some Objects have run time dependencies, which should be resolved on request, and which are different on each intance. I.e.: the Buffer:
1 2 3 4 5
|
container.resolve<Buffer>(TYPE_STATIC, sizeof(Vertex), 4);
container.resolve<Buffer>(TYPE_STATIC, sizeof(Vertex), 36);
or combined
container.resolve<Mesh>( container.resolve<Buffer>(TYPE_STATIC, sizeof(Vertex), 4));
|
By this reason I would use a Lambda expression to create an object of a buffer like this and register it as delegate:
|
container.register<Buffer, Buffer::eType, int, int>([&](Buffer::eType type, int size, int count) -> Buffer * {return new Buffer(type, size, count);};
|
The resolve should get the correct Lambda expression from map based on resolve type and invoke the delegate with given arguments ...
To use the benefit of an IOC container, there should no extra factory implementations for the registration mechanism.