michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
409 stars 114 forks source link

Empty Constructors for DI #214

Closed isaacrlevin closed 4 years ago

isaacrlevin commented 4 years ago

Hello,

I am using this to build out a .NET Core project and I am unable to wire up DI for LocalHueClient due to a missing default constructor for it. Is there any opportunity to add this?

michielpost commented 4 years ago

Which dependency injection framework are you using? Most have support for constructor parameters. For example in asp.net core: services.AddTransient<ILocalHueClient>(s => new LocalHueClient(ip));

isaacrlevin commented 4 years ago

I'm using ASP.NET Core but the issue I see is what do I do if the IP is determined at runtime?

michielpost commented 4 years ago

You can create another service / factory that creates the HueClient and use that with your DI container?

Example (you might want to store the returned hue client):

public class HueClientFactory : IHueClientFactory
{
  public ILocalHueClient GetClient(string ip)
  {
    return new LocalHueClient(ip);
  }
}