TestableIO / System.IO.Abstractions

Just like System.Web.Abstractions, but for System.IO. Yay for testable IO access!
http://www.nuget.org/packages/System.IO.Abstractions
MIT License
1.52k stars 256 forks source link

Consider making IServiceCollection extension method #604

Closed GeeWee closed 4 years ago

GeeWee commented 4 years ago

Is your feature request related to a problem? Please describe. When using the built in ASP.NET core dependency injection, I often have to write code like this:

services.AddTransient<IFileSystem, FileSystem>();
services.AddTransient<IDirectory, DirectoryWrapper>();
services.AddTransient<IFileInfoFactory>((provider) => provider.GetService<IFileSystem>().FileInfo);

Describe the solution you'd like It would be nice if System.IO.Abstractions defined an extension method on IServiceCollection like AddPhysicalFileSystem which made sure to register all the necessary dependencies in the DI container.

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label type: enhancement to this issue, with a confidence of 0.91. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

fgreinacher commented 4 years ago

This would require us to introduce a new dependency https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection.Abstractions which is not supported on .NET Framework (which we are targeting here). Also ASP.NET Core has it's own file system abstractions which I think should be prefered to "raw" I/O.

I'm therefore closing this, but anyway thanks a lot for your suggestion!

GeeWee commented 4 years ago

Perfectly fair. Thanks for considering it!

govorovvs commented 1 year ago

Let's create conditional package reference

<ItemGroup Condition="'$(TargetFramework)' != 'net461'">
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
  </ItemGroup>