I have an interface (call it IAcmeService) that has multiple implementations.
FileSystemAcmeService
DatabaseAcmeService
NetworkAcmeService
The end-user needs to be able to select which implementation will be used and also save that selection.
Currently I'm configuring my IOC container (Unity) to register all the known implemenatation with a name.
container.RegisterType(of IAcmeService, FileSystemAcmeService)("FileSystemAcmeService")
container.RegisterType(of IAcmeService, DatabaseAcmeService)("DatabaseAcmeService")
container.RegisterType(of IAcmeService, NetworkAcmeService)("NetworkAcmeService")
To allow the user to save their selection I have app.config configuration section file that stores the chosen service name to use.
To resolve the selected implementation I'm doing a manual Resolve in the Initialize method of the class the uses the service.
Private _service as IAcmeService
Public Sub Initialize()
_service = container.Resolve(of IAcmeService)(_config.AcmeServiceName)
End Sub
This doesn't seem right because my class has to know about the container. But I can't figure out another way.
Are there other ways to allow end-user selection without the class knowing about the container?