Open SteRoh opened 7 months ago
Note sure why scoped instance would not participate in the scope deduction for nested types but that seems the case. It might be easier to create a logger with di as well. That seems to work but not sure whether it fits your use case? https://godbolt.org/z/ejrT6hqK3
Thx for the impressing fast response @krzysztof-jusiak :)
I stripped down the Problem to this simple example but my actual use case looks like this:
create std::shared_ptr<logger>
So within the injector i need one LoggerFactory and i thought i have to bind the const std::shared_ptr<logger>&
to the create() Function of the LoggerFactory.
https://godbolt.org/z/YTbbo15rY I have no idea what to do inside the injector :)
Maybe there is an easy solution, but i could not find any examples which show this factory Use case.
Context
In my case i want to share a logger instance through my classes therefore I pass some
const std::shared_ptr<T>&
into my classes.Actually i cant change my constructor arguments, because i have to check if boost::di can be used non-invasive. Is there a way to enforce the right deduction of
const std::shared_ptr<T>&
? Or how to handle this case?Expected Behavior
Each instance of my class is using the same logger.
Actual Behavior
The Logger which shall be passed by
const std::shared_ptr<T>&
is somehow dangling. In my example, it is obv not the same logger instance. Even the address sanitizer is complaining.Steps to Reproduce the Problem
const std::shared_ptr<logger>& log
Specifications