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

Fixed and issue I found on first use that required IServiceProvider #152

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/StreamDeckLib/ActionManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
Expand All @@ -24,6 +25,8 @@ public partial class ActionManager : IDisposable
// The logger we will receive when being instantiated. Defaults to a NullLogger is none is specified.
private readonly ILogger<ActionManager> _Logger;

private readonly IServiceProvider _serviceProvider;

#endregion


Expand All @@ -39,9 +42,10 @@ private ActionManager()
/// Initializes a new instance of the <see cref="T:StreamDeckLib.ActionManager"/> class.
/// </summary>
/// <param name="logger">An instance of a logger (<see cref="ILogger"/> class.</param>
public ActionManager(ILogger<ActionManager> logger = null) : this()
public ActionManager(ILogger<ActionManager> logger = null, IServiceProvider serviceProvider = null) : this()
{
this._Logger = logger ?? NullLoggerFactory.Instance.CreateLogger<ActionManager>();
this._serviceProvider = serviceProvider;
}

#endregion
Expand Down Expand Up @@ -140,7 +144,7 @@ public TActionType GetActionInstance<TActionType>(ConnectionManager connectionMa

if (this._Actions.ContainsKey(actionUUID))
{
var instance = Activator.CreateInstance(this._Actions[actionUUID]) as TActionType;
var instance = ActivatorUtilities.CreateInstance(this._serviceProvider, this._Actions[actionUUID]) as TActionType;
instance.Logger = _Logger;
instance.Manager = connectionManager;
return instance;
Expand Down Expand Up @@ -187,7 +191,7 @@ private BaseStreamDeckAction CreateActionInstanceByUUID(ConnectionManager connec
this._Logger?.LogTrace($"{nameof(ActionManager)}.{nameof(CreateActionInstanceByUUID)}(string, bool)");
if (this._Actions.ContainsKey(actionUuid))
{
var instance = Activator.CreateInstance(this._Actions[actionUuid]) as BaseStreamDeckAction;
var instance = ActivatorUtilities.CreateInstance(this._serviceProvider, this._Actions[actionUuid]) as BaseStreamDeckAction;
instance.Logger = _Logger;
instance.Manager = connectionManager;
return instance;
Expand Down
16 changes: 11 additions & 5 deletions src/StreamDeckLib/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ public ConnectionManager(IOptions<StreamDeckToolkitOptions> options, ActionManag
_ActionManager = actionManager;
_logger = logger;

var myInfo = JsonConvert.DeserializeObject<Info>(options.Value.Info);
Info = myInfo;
_port = options.Value.Port;
_uuid = options.Value.PluginUUID;
_registerEvent = options.Value.RegisterEvent;
if (options.Value != null)
{
if (!string.IsNullOrEmpty(options.Value.Info))
{
var myInfo = JsonConvert.DeserializeObject<Info>(options.Value.Info);
Info = myInfo;
}
_port = options.Value.Port;
_uuid = options.Value.PluginUUID;
_registerEvent = options.Value.RegisterEvent;
}
_proxy = streamDeckProxy;
}

Expand Down