If you have stored an instance of the ConnectionMonitor class in your WorkItem, you can reference it from any other class within the scope of that WorkItem. You can use a [ServiceDependency] attribute on a parameter of the class constructor to accept an injected reference and store it in a class-level variable.
public class MyNewClassAlternatively, you can expose a public property for the ConnectionMonitor and have ObjectBuilder set it to the ConnectionMonitor instance in the WorkItem.
{
private ConnectionMonitor sampleMonitor;
public MyNewClass([ServiceDependency] ConnectionMonitor cm)
{
this.sampleMonitor = cm;
}
...
}
public class MyNewClassAnother approach is to directly query the Services collection of the WorkItem to obtain a reference to the service you want.
{
private ConnectionMonitor sampleMonitor;
[ServiceDependency]
public ConnectionMonitor ConnectionMonitor
{
get { return this.sampleMonitor; }
set { this.sampleMonitor = value; }
}
...
}
public class MyNewClass
{
private ConnectionMonitor sampleMonitor;
public MyNewClass();
{
this.sampleMonitor = myWorkItem.Services.Get();
}
...
}
No comments:
Post a Comment