Created
December 16, 2019 09:38
-
-
Save mrtank/fe312eecc1ded16df50de5e0138b01f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class ApiCaller | |
{ | |
... | |
public TRecord Get< TRecord >( string url ) | |
{ | |
TRecord item = default( TRecord ); | |
try | |
{ | |
var response = GetHttpClient( ).GetAsync( $"{url}" ).Result; | |
EnsureSuccessStatusCode( response ); | |
item = response.Content.ReadAsAsync<TRecord>( ).Result; | |
} | |
catch ( Exception ex ) | |
{ | |
LogAndThrowException( ex ); | |
} | |
return item; | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class DataAccess : IDALXYInterface | |
{ | |
// usually calling from that | |
public List<SomeDTO> GetSomething( long id ) | |
{ | |
return DataAccessHelper.HandleCalling( NLog.LogManager.GetCurrentClassLogger( ), ( ) => | |
{ | |
return new XYAPICaller( ).Get<List<SomeDTO>>( "someUrl" ); | |
} ); | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static TResult HandleCalling< TResult >( NLog.ILogger logger, Func<TResult> func, | |
[System.Runtime.CompilerServices.CallerMemberName] | |
string callerName = null ) | |
{ | |
try | |
{ | |
logger?.Trace( "[Start] {0}", callerName ); | |
var actionResult = func( ); | |
return actionResult; | |
} | |
catch ( ServiceReferenceException ) | |
{ | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// that sneaky one left out of DataAccessHelper.HandleCalling. Also it's not clear if it's left out of DataAccessHelper.HandleCalling, | |
// because I have to check inside GetXY, if the wrapping is inside there... | |
return new XYAPICaller().GetXY( url ); | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment