structuremap - C# OOPS and structure map -
i need suggestion on below scenario :
i have icacheprovider
interface , using structure map. icacheprovider
has dbcacheprovider
, memorycacheprovider
, rediscacheprovider
. during initializing icacheprovider
during memorycacheprovider
. code :
for<icacheprovider>().use(new memorycacheprovider());
now in controller/manager injecting :
public class searchmanager: isearchmanager { private readonly isearchrepository _searchrepository; private readonly icacheprovider _cacheprovider; public searchmanager(isearchrepository searchrepository, icacheprovider cacheprovider) { _searchrepository = searchrepository; _cacheprovider = cacheprovider; } public async task<arrayofordersearchresponse> retrievesearchdata(searchtype searchtype) { //check if search data exists in cache. var searchcachekey = searchcacheprefix + searchtype.tostring(); var searchdata = _cacheprovider.get(searchcachekey, typeof(arrayofordersearchresponse)); if (searchdata == null) { //search data not in cache, call source search service data , cache it. searchdata = await _searchrepository.retrievesearchdata(searchtype); _cacheprovider.create(searchcachekey, searchdata, 60); //durationinseconds } return searchdata arrayofordersearchresponse; } }
question : if need assign dbcacheprovider
or rediscacheprovider
instead of memorycacheprovider
_cacheprovider
in searchmanager
how achieve @ runtime?
thank you.
Comments
Post a Comment