We will be using this PR following EnvironmentVariableService
as a model for adding a new service.
The following steps are distilled and organized from that PR.
- Create your new service interface in
src/Microsoft.ComponentDetection.Contracts/IMyNewService.cs
- Create your new service implementation in
src/Microsoft.ComponentDetection.Common/MyNewService.cs
implementing and exportingIMyNewService
.
using System;
using System.Composition;
using Microsoft.ComponentDetection.Contracts;
namespace Microsoft.ComponentDetection.Common
{
[Export(typeof(IMyNewService))]
public class MyNewService : IMyNewService
{
...
}
}
- Add your new service to
src/Microsoft.ComponentDetection.Contracts/IDetectorDependencies.cs
namespace Microsoft.ComponentDetection.Contracts
{
public interface IDetectorDependencies
{
...
IMyNewService MyNewService { get; set; }
}
}
- Add your new service to
src/Microsoft.ComponentDetection.Common/DetectorDependencies.cs
namespace Microsoft.ComponentDetection.Common
{
[Export(typeof(IDetectorDependencies))]
public class DetectorDependencies : IDetectorDependencies
{
...
[Import]
public IMyNewService MyNewService { get; set; }
}
}
- Add your new service to
src/Microsoft.ComponentDetection.Contracts/Internal/InjectionParameters.cs
namespace Microsoft.ComponentDetection.Contracts.Internal
{
internal class InjectionParameters
{
internal InjectionParameters(IDetectorDependencies detectorDependencies)
{
...
myNewServiceStatic = detectorDependencies.MyNewService;
}
}
...
private static IMyNewService myNewServiceStatic;
...
[Export(typeof(IMyNewService))]
public IMyNewService MyNewService => myNewServiceStatic;
}