Skip to main content
Tweeted twitter.com/#!/StackProgrammer/status/442701952745754624
rm tag from title; added tag
Link
svick
  • 10.2k
  • 1
  • 40
  • 54

Designing interfaces and async in C#

deleted 1 characters in body
Source Link
fex
  • 289
  • 3
  • 8

Suppose I have created interface IFolderRepository with methods like that:

IEnumerable<IFolder>IEnumerable<Folder> GetAllFolders(); Folder GetFolderWithId(int id); void AddFolder(Folder newFolder); void ModifyFolder(Folder folderToModify, Folder folderAfterModification); void RemoveFolder(Folder folderToRemove); 

and I've implemented DatabaseFolderRepository and lets say CacheFolderRepositoryDecorator. Now 'hundreds of lines later' I'd like to add SkyDrive folders functionallity so I'm ready to add SkyDriveFolderRepository. Unfortunately while DatabaseFolderRepository implementation used synchronous methods to talk with database, skydrive one uses a lot of async and await. What to do in such case? In case of void methods marking it async is not a solution (need to exception handling). Should I change interface to return Task<T>? Sure it will work in above example but they're just 2 interface implementation classes. Or should most of my interfaces have Task return types (against you aren't gonna need it rule)?

Suppose I have created interface IFolderRepository with methods like that:

IEnumerable<IFolder> GetAllFolders(); Folder GetFolderWithId(int id); void AddFolder(Folder newFolder); void ModifyFolder(Folder folderToModify, Folder folderAfterModification); void RemoveFolder(Folder folderToRemove); 

and I've implemented DatabaseFolderRepository and lets say CacheFolderRepositoryDecorator. Now 'hundreds of lines later' I'd like to add SkyDrive folders functionallity so I'm ready to add SkyDriveFolderRepository. Unfortunately while DatabaseFolderRepository implementation used synchronous methods to talk with database, skydrive one uses a lot of async and await. What to do in such case? In case of void methods marking it async is not a solution (need to exception handling). Should I change interface to return Task<T>? Sure it will work in above example but they're just 2 interface implementation classes. Or should most of my interfaces have Task return types (against you aren't gonna need it rule)?

Suppose I have created interface IFolderRepository with methods like that:

IEnumerable<Folder> GetAllFolders(); Folder GetFolderWithId(int id); void AddFolder(Folder newFolder); void ModifyFolder(Folder folderToModify, Folder folderAfterModification); void RemoveFolder(Folder folderToRemove); 

and I've implemented DatabaseFolderRepository and lets say CacheFolderRepositoryDecorator. Now 'hundreds of lines later' I'd like to add SkyDrive folders functionallity so I'm ready to add SkyDriveFolderRepository. Unfortunately while DatabaseFolderRepository implementation used synchronous methods to talk with database, skydrive one uses a lot of async and await. What to do in such case? In case of void methods marking it async is not a solution (need to exception handling). Should I change interface to return Task<T>? Sure it will work in above example but they're just 2 interface implementation classes. Or should most of my interfaces have Task return types (against you aren't gonna need it rule)?

Source Link
fex
  • 289
  • 3
  • 8

Designing interfaces and async in C#

Suppose I have created interface IFolderRepository with methods like that:

IEnumerable<IFolder> GetAllFolders(); Folder GetFolderWithId(int id); void AddFolder(Folder newFolder); void ModifyFolder(Folder folderToModify, Folder folderAfterModification); void RemoveFolder(Folder folderToRemove); 

and I've implemented DatabaseFolderRepository and lets say CacheFolderRepositoryDecorator. Now 'hundreds of lines later' I'd like to add SkyDrive folders functionallity so I'm ready to add SkyDriveFolderRepository. Unfortunately while DatabaseFolderRepository implementation used synchronous methods to talk with database, skydrive one uses a lot of async and await. What to do in such case? In case of void methods marking it async is not a solution (need to exception handling). Should I change interface to return Task<T>? Sure it will work in above example but they're just 2 interface implementation classes. Or should most of my interfaces have Task return types (against you aren't gonna need it rule)?