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

fo-dicom v5 Dependency Injection Documentation #1773

Open
aarondglover opened this issue Apr 23, 2024 · 3 comments
Open

fo-dicom v5 Dependency Injection Documentation #1773

aarondglover opened this issue Apr 23, 2024 · 3 comments

Comments

@aarondglover
Copy link

To make Fellow Oak DICOM use Microsoft.Extensions.Logging, you need to use dependency injection.

If you are using the host builder from ASP.NET Core, you can do this:

var host = Host.CreateDefaultBuilder(args)
    .ConfigureLogging(logging =>
    {
        logging.ClearProviders();
        logging.AddConsole();
        logging.SetMinimumLevel(LogLevel.Information);
    })
    .ConfigureServices(services =>
    {
        services.AddFellowOakDicom();
        services.AddHostedService<Worker>();
        // This will be injected into the DICOM service
        services.AddSingleton<CustomDependency>();
    })
    .Build();

// This is still necessary for now, but we want to get rid of this in the long term
DicomSetupBuilder.UseServiceProvider(host.Services);

host.Run();

If you are not using the host builder, you'll need to make your own service collection:

var services = new ServiceCollection();
services.AddLogging(logging =>
{
    logging.ClearProviders();
    logging.AddConsole();
    logging.SetMinimumLevel(LogLevel.Information);
});
services.AddFellowOakDicom();
var serviceProvider = services.BuildServiceProvider();
DicomSetupBuilder.UseServiceProvider(serviceProvider);

Originally posted by @amoerie in #1627 (comment)

The above post is gold - and is the first time I've seen a clear example of using DI with fo-dicom v5. Dependency injection documentation, samples would be very useful

@aarondglover
Copy link
Author

Seems I am still having trouble with Dependency injection of additional objects into my DICOMService

Further discussion at #1774 (comment)

@amoerie
Copy link
Collaborator

amoerie commented Apr 23, 2024

I suspect you are running into this issue: #1611 (comment)

Can you check?

Edit: replied to wrong thread, I'll add the same reply over at #1774

@aarondglover
Copy link
Author

@amoerie as you suspected - it was exactly the issue you thought... the first x number of parameters MUST match exactly on type Thanks for your prompt assistance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants