-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FeatureRequest] Fluent lifetime management #42
Comments
Hey, This will give (maybe again sorry) you a look at the resolution mechanism: class ThreadLocal
{
public:
ThreadLocal(shared_ptr< Container >& container,
shared_ptr< TransientDependency > transientDependency,
shared_ptr< SingleInstanceDependency > singleInstanceDependency)
{
ContainerBuilder builder;
builder.registerType< UnknownSingleFromTopLevel >().singleInstance();
auto nestedContainer = builder.buildNestedContainerFrom(*container);
m_worker = nestedContainer->resolve< Worker >();
}
};
class Worker
{
public:
Worker(shared_ptr< TransientDependency > transientDep,
shared_ptr< SingleInstanceDependency > singleInstanceDep,
shared_ptr< NotThreadLocalSingleInstanceDep > notThreadLocalSingleInstanceDep,
shared_ptr< UnknownToTopLevelSingleInstance > unknownToTopLevelSingleInstance);
}; now the configuration: ContainerBuilder builder;
builder.registerType< SingleInstanceDependency >().singleInstance();
builder.registerType< NotThreadLocalSingleInstanceDep >().singleInstance();
auto container = builder.build();
for (auto i = 0; i < 8; ++i)
{
thread([=]() { container->resolve< ThreadLocal >(); });
}
So I guess you could split the configuration like so:
Am I missing something or does this achieves your goal? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
As far as I am concerned there are only 3 ways to manage the dependency lifetime. We could either specifically say there should be a single instance:
or we could use single instance for child container living as long as long child container exist. The last way is default behaviour which I believe is one instance per resolve.
In our application we are concerned about very strong multi-threading. In such scenarios we might want:
So the proposal is to add another syntax like:
InstancePerThreadLifetimeManager
is an implementation ofLifetimeManagerObject
exposing the following methods:LifetimeManager has to have access to
getOrCreateComponent
method so it can makeHypodermic
create new instances.with
std::thread::get_id
we would be able to implement LifetimeManager so it distributes instances of requested object so there is always exactly one instance per thread. Such implementation injection allows us to fully customize the objects lifetime which is crucial for multi-threading project.Thanks,
Patryk
The text was updated successfully, but these errors were encountered: