0

I have a C# class called FileTransferManager. Previously it took some parameters such as a username and password to connect to a FTP server. However now I have an additional requirement to support login using a private key. I'm using the Renci.SshNet library for the file transfers. This library supports both methods of login, so that's not a problem. However, I decided to use the factory pattern to produce some classes from the library that I need to instantiate, such as SftpClient and PrivateKeyFile; these have several constructors to take various types of data, and I want to support multiple options.

My problem is that when I create an IFactory<T> interface and implement it, e.g. PasswordSftpClientFactory : IFactory<SftpClient>, I get errors in the code that calls my FileTransferManager, saying that I need to add a reference to Renci.SshNet. I was hoping to keep that library an "internal" dependency of FileTransferManager - not sure if that's the correct term, but I mean a dependency that does not "leak" to callers of FileTransferManager. I don't want to have to add a reference to an implementation detail of FileTransferManager just because I'm using the factory pattern.

So, how can I create a factory that produces the SftpClient and PrivateKeyFile objects without introducing a transitive dependency on Renci.SshNet? Is this where the FactoryFactory meme came from?

3
  • 3
    Factory pattern should not use generics. That your code uses generics tells me you are doing something wrong and that you misunderstood the factory pattern.
    – Euphoric
    Jan 29, 2021 at 15:48
  • 1
    Oh, yeah, if I use an ISftpClientFactory interface, then I don't get the reference error.
    – ekolis
    Jan 29, 2021 at 16:08
  • This question would benefit greatly from an MCVE. Show us some code. Your plain English description of the design does not tell us what is wrong.
    – John Wu
    Jan 30, 2021 at 6:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.