Skip to content

Add support for using as a library聽#728

Closed

Description

@edena-legit

Hi 馃憢
Currently, it seems that the only way to use this tool is by command line.
It seems that the DI registration is using AsSingleton for all the components and not a scoped instance, leading to errors between calls because of the states the detectors are using.
It will be very appreciated if docs on how to use this tool as a library will be added (as it states in the README.md that it could)

AB#2097602

Activity

  1. melotic commented on Aug 17, 2023

    @melotic
    Contributor

    Hi,

    CD is supported as using a library. You'd have to use DI to resolve a IBcdeScanExecutionService and run ExecuteScanAsync.

    You can use the extension method AddComponentDetection to your ServiceCollection to register all dependencies.

    public static IServiceCollection AddComponentDetection(this IServiceCollection services)

    It seems that the DI registration is using AsSingleton for all the components and not a scoped instance, leading to errors between calls because of the states the detectors are using.

    Can you share the exact error?

  2. edena-legit commented on Aug 20, 2023

    @edena-legit
    Author

    Seems like there are detectors that holds state which leads to errors between calling such as:

       at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
       at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
       at Microsoft.ComponentDetection.Detectors.NuGet.NuGetProjectModelProjectCentricComponentDetector.OnDetectionFinishedAsync()
       at Microsoft.ComponentDetection.Contracts.FileComponentDetector.ProcessAsync(IObservable`1 processRequests, IDictionary`2 detectorArgs)
       at Microsoft.ComponentDetection.Contracts.FileComponentDetector.ExecuteDetectorAsync(ScanRequest request)
       at Microsoft.ComponentDetection.Orchestrator.Services.DetectorProcessingService.WithExperimentalScanGuardsAsync(Func`1 detectionTaskGenerator, Boolean isExperimentalDetector, DetectorExecutionTelemetryRecord telemetryRecord)
       at Microsoft.ComponentDetection.Orchestrator.Services.DetectorProcessingService.<>c__DisplayClass4_0.<<ProcessDetectorsAsync>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
       at Microsoft.ComponentDetection.Orchestrator.Services.DetectorProcessingService.ProcessDetectorsAsync(IDetectionArguments detectionArguments, IEnumerable`1 detectors, DetectorRestrictions detectorRestrictions)
       at Microsoft.ComponentDetection.Orchestrator.Services.BcdeScanExecutionService.ExecuteScanAsync(IDetectionArguments detectionArguments)
    
  3. edena-legit commented on Aug 20, 2023

    @edena-legit
    Author

    I'm receiving the following error as well:

    Base path has not yet been initialized in File Writing Service! 
    
    Microsoft.ComponentDetection.Commonexception.StackTraceString: 
    at Microsoft.ComponentDetection.Common.FileWritingService.EnsureInit()
    at Microsoft.ComponentDetection.Common.FileWritingService.ResolveFilePath(String relativeFilePath)
    at Microsoft.ComponentDetection.Orchestrator.Experiments.DefaultExperimentProcessor.ProcessExperimentAsync(IExperimentConfiguration config, ExperimentDiff diff)
    at Microsoft.ComponentDetection.Orchestrator.Experiments.ExperimentService.FinishAsync()
    

    Running as a library, I don't expect the file-writing service to do anything, right?

  4. edena-legit commented on Aug 23, 2023

    @edena-legit
    Author

    Justin Perez (@melotic), Anything on that?

  5. melotic commented on Aug 28, 2023

    @melotic
    Contributor

    I'm receiving the following error as well:

    Base path has not yet been initialized in File Writing Service! 
    
    Microsoft.ComponentDetection.Commonexception.StackTraceString: 
    at Microsoft.ComponentDetection.Common.FileWritingService.EnsureInit()
    at Microsoft.ComponentDetection.Common.FileWritingService.ResolveFilePath(String relativeFilePath)
    at Microsoft.ComponentDetection.Orchestrator.Experiments.DefaultExperimentProcessor.ProcessExperimentAsync(IExperimentConfiguration config, ExperimentDiff diff)
    at Microsoft.ComponentDetection.Orchestrator.Experiments.ExperimentService.FinishAsync()
    

    Running as a library, I don't expect the file-writing service to do anything, right?

    Call Init in the file writer service, or register a service that does nothing.

    this.fileWritingService.Init(argumentSet.Output);

  6. locked and limited conversation to collaborators on Aug 31, 2023
  7. converted this issue into a discussion #759 on Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions