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

Dependency Injection for Implementations #80

Closed
grahamehorner opened this issue Dec 5, 2018 · 4 comments
Closed

Dependency Injection for Implementations #80

grahamehorner opened this issue Dec 5, 2018 · 4 comments
Labels
area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio Design Discussion Ongoing discussion about design without consensus enhancement New feature or request

Comments

@grahamehorner
Copy link

Please consider a lightweight IoC/DependencyInjection for driver implementations, ie DeviceDriverCollection.Add(options =>{ ... }); similar to the IServiceCollection so that a developer may register driver implementation base on custom logic and allow injection of the implementation into the constructor of the driver consumer(s)

@joperezr joperezr added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Dec 5, 2018
@joperezr
Copy link
Member

joperezr commented Dec 5, 2018

I'm not sure I understand what would be the advantages of having this. Would you mind providing an Api proposal that would have more details and samples into how this would be used? Here is an example of a good Api Proposal: https://github.com/dotnet/corefx/issues/271

@joshfree
Copy link
Member

joshfree commented Dec 5, 2018

@grahamehorner for layering reasons, we're currently not planning to take a dependency on the higher level Microsoft.Extensions.DependencyInjection assembly from this low level hardware abstraction. However, with the current API you can specify a custom device driver by inheriting from the GpioDriver abstract class and passing it as a parameter to the GpioController ctor.

Does this satisfy the needs of your scenario?

https://github.com/dotnet/iot/blob/master/src/System.Device.Gpio/System/Device/Gpio/GpioDriver.cs
https://github.com/dotnet/iot/blob/master/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs#L39

        using (GpioController controller = new GpioController(myNumberingScheme, myCustomGpioDriver))
        {
            controller.OpenPin(pin, PinMode.Output);

@grahamehorner
Copy link
Author

@joshfree while I understand not wishing to take a dependency on a higher level assembly; I do believe the that driver abstraction/implementations should be held in some kind of registry and/or a simple DI system; this would allow greater flexibility/testability for developers with minimal code change; swapping drivers by way of change the registration/configuration and not code.

eg. the registration of an the implementation of VirtualGpioDriver, the options type associated with the driver options and an optional action to perform additional configure of the driver at runtime construction/instantiation.

System.Device.DriverRegistry.Register<TDriver,TDriverOptions>(string driverName, Action<TDriverOptions> options)

using(var driver = System.Device.DriverRegistry.Resolve<GpioDriver>("driverName",(options)=>
{ 
options.someConfiguration = 12;
}))
{
driver.doSomeWork();
}

@joperezr joperezr added the area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins label Feb 11, 2019
joperezr pushed a commit to joperezr/iot that referenced this issue Feb 19, 2019
Add DockerFiles for new Helix support
@krwq krwq added this to the Future milestone Feb 22, 2019
@joperezr joperezr added area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio Design Discussion Ongoing discussion about design without consensus enhancement New feature or request and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins labels Apr 17, 2019
@krwq
Copy link
Member

krwq commented Jan 7, 2021

[Triage] This seems to bit a bit out of scope of this project. It adds too much overhead for most common scenarios. If we want to have something like that it should be an additional package.

@krwq krwq closed this as completed Jan 7, 2021
@dotnet dotnet locked as resolved and limited conversation to collaborators Feb 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio Design Discussion Ongoing discussion about design without consensus enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants