Skip to content
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

[Question] How to use Chained for multiple Classes within many DLL's #267

Open
Smurf-IV opened this issue Aug 17, 2023 · 0 comments
Open

Comments

@Smurf-IV
Copy link

scenario
I want use DI / IoC style creation in Several Exported Classes from several DLL's

For DLL that has several classes I am using chaining:

CDoMagic::CDoMagic(plog::Severity severity, plog::IAppender* appender)
{
    plog::init(severity, appender);    // Initialize the shared library logger.
    PLOGI << "CDoMagic Created";
}

CDoMgic2::CDoMgic2(plog::Severity severity, plog::IAppender* appender)
{
    plog::init(severity, appender);    // Initialize the shared library logger.
    PLOGI << "CDoMgic2 Created";
}

Each time an instance of the classes are constructed a new static instance is created behind the scenes;
So when PLOG## is called it will log out several times, because there are several instance of the logger
e.g. in the following CDoMgic2 has been created twice, but the 2nd instance is logging out 3 times.

2023-08-17 14:28:48.507 INFO  [21584] [CDoMagic::CDoMagic@9] CDoMagic Created
2023-08-17 14:28:48.509 INFO  [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
2023-08-17 14:28:48.509 INFO  [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
2023-08-17 14:28:48.511 INFO  [21584] [CDoMgic2::~CDoMgic2@14] CDoMgic2 Destroyed
2023-08-17 14:28:48.511 INFO  [21584] [CDoMgic2::~CDoMgic2@14] CDoMgic2 Destroyed
2023-08-17 14:28:48.513 INFO  [21584] [CDoMagic::~CDoMagic@14] CDoMagic Destroyed
2023-08-17 14:28:48.513 INFO  [21584] [CDoMagic::~CDoMagic@14] CDoMagic Destroyed
2023-08-17 14:28:48.518 INFO  [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
2023-08-17 14:28:48.518 INFO  [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created
2023-08-17 14:28:48.518 INFO  [21584] [CDoMgic2::CDoMgic2@9] CDoMgic2 Created

code to demonstrate above:

    {
        CDoMagic DoMagic(plog::get()->getMaxSeverity(), plog::get() );
        CDoMgic2 DoMagic2(plog::get()->getMaxSeverity(), plog::get());
    }
    CDoMgic2 DoMagic2(plog::get()->getMaxSeverity(), plog::get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant