Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:09

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 14 13:05

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 14 13:04
    krzysztof-jusiak commented #452
  • Dec 14 13:04

    krzysztof-jusiak on cpp14

    "Diagnostic push" moved to avoi… (compare)

  • Dec 14 13:04
    krzysztof-jusiak closed #452
  • Dec 14 08:10
    m-gaj commented #452
  • Dec 14 07:59
    m-gaj synchronize #452
  • Dec 14 00:08

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 13 02:58
    krzysztof-jusiak commented #452
  • Dec 12 17:56
    m-gaj opened #452
  • Dec 12 00:07

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 10 00:06

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 09 00:04

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 08 00:04

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 07 00:03

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 05 00:01

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 03 00:01

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Dec 01 00:00

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Nov 29 23:59

    krzysztof-jusiak on gh-pages

    doc update (compare)

  • Nov 27 23:59

    krzysztof-jusiak on gh-pages

    doc update (compare)

Kris Jusiak
@krzysztof-jusiak
class C
{
public:
    C(A& a):m_a(a) {}
    void go()
    {
        m_a.doSomething();
    }

private:
    A& m_a;
};

int main()
{
    auto in1 = di::make_injector(di::bind<A>().to<B>(),
                                di::bind<std::string>().to("Jump!")); //I need set this "Jump!" value.
    auto a = in1.create<std::shared_ptr<A>>();
    a->doSomething();

    auto objA = std::make_unique<B>(); // default ctor
    auto in2 = di::make_injector(di::bind<A>().to(*objA));

    auto c = in2.create<C>();
    c.go(); //This call type "Do nothing."
    objA->setDo("Go back.");
    c.go(); //call changed go(). With this call I want to type "Go back."
}
will print:
Jump!
Do nothing.
Go back.
If it comes to default values you may take a look into 'constructor extension' which allows to define what constructor should be taken; this way you redefine your constructor once to be with a parameter and once without; the latter will inject default then.
Extension might be found here -> http://boost-experimental.github.io/di/extensions/index.html#constructor-bindings
Travis
@travisdoor
I've created my first app using Boost.DI and now I feel like I should refactor everything I've ever done in c++! :smile: Really good job!
Travis
@travisdoor

Hi,
is there any way how to create something like this:

    template<class T>
    static app &construct() noexcept
    {
        auto injector = di::make_injector(
            app_bindings::bind(),
            di::bind<iapp_delegate>.to<T>()
        );

        return injector.create<app &>();
    }

The app_bindings are bindings of core application compiled like shared library and I want to attach clients app_delegate implementation. So type T will be some "my_app_delegate" where I want to inject some core modules already loaded inside main application. On client side I call in main() app_factory::construct<my_app_delegate>().start();.

I'm still getting error error: expected '(' for function-style cast or type construction on create call
Travis
@travisdoor
Finally I found solution. My lib has public getter for its own injector split into definition and implementation (implementation of modules is private), return type of this function is using public_injector = di::injector<app &, interface1&, interface2&>; so I can manage what can be injected on client side. Client has injector created from own dependencies and application public_injector. Now I can do anything on client side and simply connect it with core via injection.
MattiasEppler
@MattiasEppler
Hi. This is my first application with di in c++. I already used di in c#. Now I have a question. I alredy posted the question to the comments in tutorial section. But maybe its better to discuss here

If I have a constructor with 2 parameters of the same type.
mapping_var_manager(imappable_var_manager sourceVarManager, imappable_var_manager destinationVarManager);

I load the information from json file which imappable_var_manager i have to bind to sourceVarManager and destinationVarManager. They can be the same but they have not to be the same. How to solve?

MattiasEppler
@MattiasEppler
Ok the soultion is: use named parameters.
Lea Hayes
@kruncher
Hey. I have a question regarding Boost DI. I understand roughly how to use the library but on a technical level how is the library able to discover the fields that need to be injected?
Andreas K
@vulptex
@krzysztof-jusiak , am i able to extend the bindings of a injector @ runtime?
i know make_injector is doing its meta magic @ compile time
Lea Hayes
@kruncher
@9cubes thanks for the link. The slides look interesting I wonder if there is a presentation on YouTube that includes the original talk...
Andreas K
@vulptex
Would be great if i can have ctors like this blubb(std::function<std::unique_ptr<interface_a>(void)>& func)
funny enough, boost.di does not complain about those ctors, i can construct the class via injector.
Andreas K
@vulptex
Anyone aware of issues of registering an instance directly and gcc optimizing away the ctor call?
creating a reference to a interface results in a reference to a null object..
attribute((optimize("O0"))) helps on the ctor...
than the whole instance is moved and not even copy constructed..
strange
AJoeBCool
@AJoeBCool
Hi, can anyone help me with a compilation problem? I am tying to compile the Boost.DI factory example from the extensions tutorial: http://boost-experimental.github.io/di/extensions/index.html#factory Can anyone tell me the command line to get it compiled? I tried: gcc -std=C++14 factory.cpp -I~/di/
Kris Jusiak
@krzysztof-jusiak
$pwd
boost/libs/di/extension/injections
$g++ factory.cpp -std=c++14 -I ../../include
AJoeBCool
@AJoeBCool
Thanks, that works! - Now, I have to get the factory working in my code.
Andreas K
@vulptex
Hi
Andreas K
@vulptex
is it possible to get the count of registrations?
or if someting is registered at compile time?
like: boost::di_is_registered
Andreas K
@vulptex
hey everybody, i have issues getting my injector extensible..
simple use case, i want that my registrations are always overrideable
Przemek Lach
@przemeklach
Hello. Anyone in here?
Przemek Lach
@przemeklach
Anyone manage to get CLion auto complete to work with this library? I'm trying to learn how to use this library and getting this to work would be most helpful. When I call di::make_injector() CLion tells me that the type of the resulting injector is 'unknown'.
Stephen W. Nuchia
@swn1
Hit a lifetime management issue for singletons. Using di framework in a Windows DLL, when the process unloads the DLL the singleton's destructor is called automatically. But that's too late, the object tries to do things like logging its own destruction and the support libraries have already been shut down. I'm new to this code base but didn't see anything addressing this in a quick pass through the documentation. I guess I'll go read the code :-)
Andreas K
@vulptex
Hi everybody
Andreas K
@vulptex
@krzysztof-jusiak, i have some problems understanding a problem which i have with override
would be great if you can help me out :-)
i cant do multiple boost::di::overrides
when there was already one override added to the injector, i cant override again .
juandent
@juandent
hi all
wonder if someone can give me a push with a sample that does not work as expected
I am trying to inject templates

'template <class T = class Greater>
struct example {
using type = T;
};

struct hello {};

int main() {
const auto injector = di::make_injector(
di::bind<class Greater>().to<hello>()
);

auto object = injector.create<example>();
static_assert(std::is_same<hello, decltype(object)::type>{});
}'

`template <class T = class Greater>
struct example {
using type = T;
};

struct hello {};

int main() {
const auto injector = di::make_injector(
di::bind<class Greater>().to<hello>()
);

auto object = injector.create<example>();
static_assert(std::is_same<hello, decltype(object)::type>{});
}`

the static_assert fails
juandent
@juandent
anybody?
Bohdan
@Warchant

Hi everyone. I would like to know, why binding of a vector of instances does not work

std::vector<std::shared_ptr<int>> value{std::make_shared<int>(1),
                                          std::make_shared<int>(2),
                                          std::make_shared<int>(3)};
  auto inj = boost::di::make_injector(boost::di::bind<int *[]>.to(value));
  auto v = inj.create<std::vector<std::shared_ptr<int>>>();
  ASSERT_EQ(v, value); // FAILS

Expected equality of these values:
  v
    Which is: {}
  value
    Which is: { 0x7fccba403dd8, 0x7fccba403bc8, 0x7fccba403be8 }

in the above example I create "multiple binding" to a value of vector of ptrs to ints (in my code I have interface + impl, but in this example let it be int for simplicity).

and the value is not bound. Can someone answer why?

Perhaps @krzysztof-jusiak ?

Is this a bug?

Bohdan
@Warchant

Also, small question - one of my modules accepts boost::asio::io_context& context parameter, and in injector I do not specify anything specific to this type (so it is created automatically by injector). What is the lifetime of this object? Where is it stored? Can I get reference to this object having only injector?

Can I get reference to instances created by my injector?

Bohdan
@Warchant
Can somebody look at this issue?
boost-experimental/di#429
Andreas K
@vulptex
Hi, someone here? :-)