-
Notifications
You must be signed in to change notification settings - Fork 68
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
How should I register movers? #4
Comments
I still need to write some documentation on this, though I'm not really sure the current manually 'registering'-approach is the right one. However, I've added a test for Registration that should give you some impression how it works. The same can be done for Basically, moving files between two (or the same) physical filesystems should be fast. If the The initial registration step might be simplified by adding a extension/static method to easily register the DefaultEntityMover and PhysicalEntityMover. Also, wrapping About using MEF, or some kind of DI. Not all DIs support matching on two generic types. I don't want to depend on a single one, because that can be extremely annoying. |
I’m actually more worried about atomic operations than performance myself. When accessing a filesystem with a Windows API mindset, setting a file’s contents transactionally can be accomplished with a combination of
Wrapping is an issue when trying to implement atomic operations using the registration+extension methods style. For
I understand. Choosing a particular DI framework can add baggage and scare away potential adopters. I’ve yet to think up a good way to handle this. I do like MEF myself but there’s no need for SharpFileSystem to adopt it for me to use it ;-). One thought I have had on this, however, is how the registration is
I think it would be much easier to support composition systems and various scenarios if the registration wasn’t static but instead attached to some sort of context which maintains non-static registrations. This would, unfortunately, make filesystem access more verbose, but that could be mitigated by including the root filesystem as part of the interface. Something like:
If you like that idea and we can go that route, I would very much like to remove the existing static registrations completely. Having both systems at the same time would make it somewhat easy to accidentally use the static system when wanting to buy into the context-based one. Thoughts? ;-) |
What is your specific application?
That's exactly the intention. A
Yes, making the registration non-static would solve a lot of potential problems. However, I'm not sure yet that the proposed solution is the right one. I imagine that there isn't a single 'root' filesystem. Two physical flesystems can be completely separate, not combined with a mounted or merged filesystem. If the context were to be passed to Move/Copy/Replace, why not pass the registration itself for that specific operation? public static void Move(this TypeCombinationDictionary<IEntityMover> context, FileSystemPath sourcePath, IFileSystem destinationFileSystem, FileSystemPath destinationPath) That way the system does stay flexible. What might also make the system less verbose is to wrap the context in a class:
That way any DI can inject That said, it would be nice if |
Please see my reply on #8.
Enabling concision and the existing extension pattern is the whole reason I am suggesting interfaces instead of classes here. There’s no need for
And key your extension methods granularly against each operation:
Then when you write your own code and add your own operations, you can just add another interface and inherit from the existing context class and figure out how to make that work with your DI:
Then your customized context gets all of the operations that SharpFileSystem provides as core (Copy, Move) for free and you only have one context to pass around everywhere if you want. Or, if you really wanted, you could implement
Cool! I do like how the static state enables concise calls, but I think removing them to enable DI is worth it ;-). If you’re not opposed to the contexts as interfaces as I outlined in this post, I think I could easily enough PR that. Should I go ahead? |
I was playing about and came up with this code:
However, it exits like this:
I see that there is a
PhysicalFileSystemMover
and I don’t get this error if I add this line:But is this really something I should have to orchestrate manually—it feels like I’m writing boilerplate at that point? Is there a quick shortcut to loading all such available plugins, maybe using something like MEF? Could a small snippet be added to the README to demo some simple file operations to get people started in this framework?
On the other hand, I do like that this seems to be quite extensible. The pattern used by
Move()
is something I could use to easily add a safe, transactionalReplace()
without needing to alter sharpfilesystem’s code at all.The text was updated successfully, but these errors were encountered: