Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

How to set autoreset on the timer instance? #2

@basprins

Description

@basprins

Hi,
Just came across your library. It find it a bit cumbersome to set certain properties on the timer. e.g autoReset. I need to pass this via the constructor, which is rather annoying when you combine this with e.g. autofac.

In autofac (or any IoC container I guess), I want to register a timer so that any user can get a timer injected.

something like

            builder.RegisterType<SystemTimer>().As<ISignaler>();

Now, any class that requires a timer can have an ISignaler injected. But, now the IoC container is also responsible to define the behavior of the timer. Again, e.g., the autoreset will default to true. Which should be configurable per use of the timer. I can have two classes, where one requires the autoreset to be false, and the other class requires it to be true.

Of course, I can set explicitly define how autofac should instantiate my timer

            builder.RegisterType<SystemTimer>()
                .As<ISignaler>()
                .WithParameter(new Autofac.NamedParameter("autoReset", false));

But this would mean that each class with requires an ISignaler will receive a timer with autoreset disabled.

Of course, I can work around this, but then again I need to boilerplate stuff around the SystemTimer class (e.g. make a factory), which kind of defeats the purpose all together of using this library (then I might as well rely on the .net's System timer instead).

How do you see this? Can you relate? Or have you thought about this too, and can I achieve what I want in a different way?

PS: Best regards from Nuenen ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions