I'm creating an application that creates a Catalog of files. The data of the catalog will be stored in a database through NHibernate, but the actual files are just stored on a file system. I've abstracted the interface to the file system into an interface called IFileSystemAdaptor
.
When an object is persisted from the database I need to set its IFileSystemAdaptor FileSystemAdaptor
property so that its methods and properties can access the file system.
For example a user may later call AddAttachment(string filename, Stream data)
on the persisted object. This will cause it to write the stream to the specified file name through its IFileSystemAdaptor
, and add the new file name to its AttachmenFileNames
property which will later be saved to the database.
Where can I insert code to set the the FileSystemAdaptor
property for objects that are persisted from the database? Should I add a layer of abstraction between the Session/SessionFactory that sets the FileSystemAdaptor
property before returning objects? Or is there someway I can inject this functinality into the SessionFactory
so it returns objects with the FileSystemAdaptor
already set?