Re: implicit-context v0.0.1

2023-09-30 Thread Guillaume Piolat via Digitalmars-d-announce

On Friday, 29 September 2023 at 16:56:47 UTC, Imperatorn wrote:


Sounds a bit like dependency injection but for state


Possibly, I'm not familiar with dependency injection.
When is it useful?


Re: implicit-context v0.0.1

2023-09-30 Thread evilrat via Digitalmars-d-announce
On Saturday, 30 September 2023 at 12:40:29 UTC, Guillaume Piolat 
wrote:

On Friday, 29 September 2023 at 16:56:47 UTC, Imperatorn wrote:


Sounds a bit like dependency injection but for state


Possibly, I'm not familiar with dependency injection.
When is it useful?


Dependency injection is a principle of making your 
classes/functions self-contained and isolated, it means that when 
your code might need to create a resource (such as open a file to 
write data) it is instead up to the caller to provide that 
resource, but your code never does that by itself because a 
library can't possibly know the environment and restrictions of 
the target system/machine.


Simply put, you can't possibly know how to open a file in that 
system, you can't possibly know what allocator is used in the 
caller environment (think about very low-level or bare metal 
program), and so on, so instead caller must provide everything 
that your function/method/class might need to do the work.


In the most complex situations where the entire program graph is 
about to be created in the main function there is so called DI 
containers that configures all this stuff in one central place.


Re: implicit-context v0.0.1

2023-09-30 Thread Imperatorn via Digitalmars-d-announce
On Saturday, 30 September 2023 at 12:40:29 UTC, Guillaume Piolat 
wrote:

On Friday, 29 September 2023 at 16:56:47 UTC, Imperatorn wrote:


Sounds a bit like dependency injection but for state


Possibly, I'm not familiar with dependency injection.
When is it useful?


When you want to register a bunch of objects  and then just use 
it from various places, you just state in your ctor that you want 
to use it and it will be provided by the framework.


Re: implicit-context v0.0.1

2023-09-30 Thread Max Samukha via Digitalmars-d-announce
On Saturday, 30 September 2023 at 12:40:29 UTC, Guillaume Piolat 
wrote:



When is it useful?


You can use it to troll Jonathan Blow.