-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
Using DI for FluentFTP in ASP.NET Core, NET #1199
Comments
We have interfaces you can use https://github.com/robinrodricks/FluentFTP/tree/master/FluentFTP/Client/Interfaces |
May you send some micro example? |
AsyncFtpClient implements IAsyncFtpClient, cant you use that? Manually set the properties of AsyncFtpClient once your DI container passes a concrete instance... Like
And then register the type:
|
Thank you! But If in the future you will add factory it will be cool. |
Can you give an example of what you are looking for? |
https://learn.microsoft.com/en-us/dotnet/core/extensions/httpclient-factory If we see usually variant it will be the same as using interface and init client in the constructor. But we have named client or typed client and can set client on start application and use it in other places. It will very help if for initialization we have more parameters than ip, login, password.
When need client: |
See even in this example, you are manually setting properties on Or are you asking for a Factory object and IFactory interface?? And Factory would have methods to create FtpClient and AsyncFtpClient?? |
Yes, I about a factory with methods to create FtpClient and AsyncFtpClient. And also I want to set clients parameters at start (as my example) and create tunned clients from any place. |
I can work on adding client factories if needed! @kostazol I think the reason |
@parthvnp Go ahead please! |
@robinrodricks @kostazol Here is the spec for design of FTP Client Factory
Minimal examples of the FTP Client Factory API// create a named FTP Client
IAsyncFTPClientFactory ftpFactory = new DefaultAsyncFTPClientFactory("ftp_client_v1", options => {
// setup FtpConfig options here
});
// in controller for example
public Example: ControllerBase {
private IAsyncFTPClientFactory _factory;
public Example(IAsynFTPClientFactory factory){
_factory = factory;
}
// using the factory to create FTP Client to upload files
public UploadFile(){
var client = _factory.Create("ftp_client_v1"); // throws not registered expection if the named client has not been registered
client.uploadFile(@"D:\Github\FluentFTP\README.md", "/public_html/temp/README.md);
}
} |
Everything, is great. But about "The onus of disposing the FTP client is on the user of the factory. I am still not sure on this behaviour." as I know in Microsoft.Extensions.Http usually factory control disposing. I don't know details but it helps control "connection pool" ( HTTP persistent connection ), some discution: |
@parthvnp Sounds good, you have my blessing to go ahead! |
I have moved this to the Wiki: https://github.com/robinrodricks/FluentFTP/wiki/Future-Plans |
**FluentFTP Version: 45.0.3
Framework: .NET 7
Hello. Do you have some best practices for using Fluent FTP with DI? May be FluentFTP need client factory as http client https://learn.microsoft.com/en-us/dotnet/core/extensions/httpclient-factory ?
The text was updated successfully, but these errors were encountered: