Send message with SignalR to client(s) from injected (IoC) method I am new with SignalR and still a newbie with IoC Container SimpleInjector and I am wondering if there are any side effects and/or if I'm save with my chosen approach.

In my web app I have a SetupHub that invokes a method on an object resolved with SimpleInjector. This method may do anything that I'm not aware about. Maybe it contains Tasks and it may consume x units of time.

During this Setup process I want to inform the client of the progress. This is my current implementation and it works fine:

public class SetupHub : Hub
{
    public void Start()
    {
        // My SimpleInjector resolve wrapper
        IocContainer.Instance.GetInstance&lt;ISetup&gt;().Start(UpdateProgress);
    }

    private void UpdateProgress(double percentage)
    {
        Clients.Caller.updateProgress(percentage);
    }
}


public class Setup : ISetup
{
    public void Start(Action&lt;double&gt; updateProgress)
    {
        Task.Factory.StartNew(() =&gt;
                              {
                                  updateProgress(10); // Bogus progress
                                  Thread.Sleep(100);  // Simulate x units of time
                                  CreateRoles();
                                  updateProgress(25);
                                  Thread.Sleep(400);
                                  CreateUsers();
                                  updateProgress(60);
                                  Thread.Sleep(200);
                                  CreateRelations();
                                  updateProgress(100);
                                  //CreateRelationGroups();
                              });
    }
}

public interface ISetup
{
    void Start(Action&lt;double&gt; updateProgress);
}
Currently, your setup doesn't allow for any cancellation or error handling. The latter is an implementation detail, so I guess you've handled that in the actual code. I would consider the following:


Return the started task out of Start
Will you ever need to provide a result from the started task? If so, provide an overload for Func&lt;double,T&gt;
Provide cancellation support via a cancellation token (if business logic dictates this is acceptable)
Provide a Stop method that also that can stop the task created by Start