Dependency Injection in DicomServers

314 views
Skip to first unread message

Jack McKay

unread,
Sep 23, 2017, 4:50:43 PM9/23/17
to Fellow Oak DICOM
Hello, I am currently planning on using fo-dicom to implement a modern PACS. For keeping the design clean and modular I would prefer to use dependency injection.

When looking at any SCP examples, I see the static Create<T> method is used to create my DicomService, but this method does not (from what I can understand) provide a simple way to support additional constructor parameters.

For example:

Within the PACS I want to implement the DICOM Store Service.
The DICOM Store Service may depend on a database access service, a settings reader, an audit logging service, etc. 

I would rather implement these dependencies as follows:

DicomStoreService : DicomService, IDicomServiceProvider, IDicomCEchoProvider
{
...
   
public DicomStoreService(INetworkStream stream, Encoding enc, Logger log, IMyInjectedService a, IMyOtherInjectedService b)
...
   
public void OnReceiveAssociationRequest(DicomAssociation association)
   
{
        _a
.DoSomething(); //Stored instance of IMyInjectedService
       
....
     
}
}

Is there a recommended way to achieve this in fo-dicom?

I originally thought of using property injection (after creation of the server) but I would rather stick to constructor injection if possible to prevent instantiation of my services without their dependencies.

Hopefully I've made this clear enough, thanks in advance!

Anders Gustafsson Cureos AB

unread,
Sep 25, 2017, 3:35:25 AM9/25/17
to Fellow Oak DICOM
Hello Jack!

Currently there is no support for what you are asking. You are limited to use the 3 parameter constructor for your DicomService implementation. One option you might be able to make use of is that the DicomService base class implements a settable property "object UserState". This could at least be a poor man's solution for what you are trying to achieve?

However, I think your idea is very good, so please feel free to post an issue in the Github repository and we will definitely consider it for implementation.

Regards,
Anders @ Cureos

Michael W.

unread,
Jan 3, 2018, 5:47:14 AM1/3/18
to Fellow Oak DICOM
Hi Jack,

I have the same issue regarding DI in SCP service. Did you already add a request in Github project? Did not find anything. Want to ask before I add another request.

Best,
Michael

Michael W.

unread,
Jan 8, 2018, 11:01:20 AM1/8/18
to Fellow Oak DICOM
Reply all
Reply to author
Forward
0 new messages