-
Notifications
You must be signed in to change notification settings - Fork 214
Refactor http to reduce static singleton dependencies #1310
Conversation
public ICryptographyManager CreateCryptographyManager() | ||
{ | ||
return new iOSCryptographyManager(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking... should this be cached? We considering the same for some of the other objects. however perhaps this doesn't pay off as those are relatively cheap objects to create. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I've changed these to be class initialized properties so they're only constructed once. #Closed
Looks great! Added a few points... most of them probably just for a quick chat. #Closed |
} | ||
//interface IHttpClientFactory | ||
//{ | ||
// IHttpClient Create(string uri, RequestContext requestContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove completely? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed #Closed
core/src/PlatformProxyFactory.cs
Outdated
#elif IS_MSAL | ||
return true; | ||
#else | ||
return true; // TODO: should we default to MSAL or should we default to throw exception? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw exception? [](start = 85, length = 16)
IMO: Throw. should not ever happen #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed #Closed
core/src/IPlatformProxy.cs
Outdated
|
||
ILegacyCachePersistance CreateLegacyCachePersistence(); | ||
ITokenCacheAccessor CreateTokenCacheAccessor(); | ||
ICryptographyManager CreateCryptographyManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made most of my comments on the "Create" pattern in the implementation class. Adding here that perhaps we should follow the lazy pattern used in the platform proxy class to create the platform information objects instead of newing "helper"objects every time? Perhaps the gain is neglectable.
My thinking is not for the client side scenarios but rather server side scenarios. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed this. please check updated code once I push. #Closed
Outside the scope of the refactoring,,, but considering introducing caching here... using well, a static given the class is static. Aside: perhaps this should really be moved to the AssemblyUtils class? [mzuber] -- I'm going to make a note in my refactoring onenote to look at cleaning up this class since I agree it's weird for us to recalculate this stuff constantly. but i'm going to push it out of this PR and do it later. #Pending Refers to: core/src/MsalIdHelper.cs:111 in e980b31. [](commit_id = e980b31, deletion_comment = False) |
|
||
using System.Threading; | ||
using Microsoft.Identity.Core.Http; | ||
|
||
namespace Microsoft.Identity.Client | ||
{ | ||
/// <summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
///
[](start = 4, length = 13)
was thinking if we can do inherit docs for both PBA and CCA? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I want to make another documentation cleanup pass. Added notes to my backlog. #Pending
/// use this it would require IL weaving, which does not seem to work on all target frameworks. | ||
/// Instead, call <see cref="EnsureModuleInitialized"/> from static ctors of public entry points. | ||
/// </remarks> | ||
internal class ModuleInitializer | ||
{ | ||
private static bool isInitialized = false; | ||
private static readonly object lockObj = new object(); | ||
private static bool _isInitialized = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_isInitialized [](start = 28, length = 14)
should this be volatile ? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. fixed. #Closed
@@ -137,7 +137,7 @@ private void Log(LogLevel msalLogLevel, string messageWithPii, string messageScr | |||
? string.Empty | |||
: " - " + CorrelationId; | |||
|
|||
var msalIdParameters = MsalIdHelper.GetMsalIdParameters(new PlatformInformation()); | |||
var msalIdParameters = MsalIdHelper.GetMsalIdParameters(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msalIdParameters [](start = 16, length = 16)
can this be "cached" for the lifetime of logger? perhaps even injected at creation time (or static ctr) #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it can be. backlog of notes for future refactor. #Pending
} | ||
//internal abstract class PlatformInformationBase : CorePlatformInformationBase | ||
//{ | ||
//} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove completely ? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed #Closed
some of these change reminds me .... I feel we are missing micro/macro performance tests which can quickly help assess whether we will improve especially service performance... which is overall my biggest concern for the library when it comes to performance and memory usage #Pending |
Assert.AreEqual("MSAL.Desktop", qp["x-client-sku"]); | ||
Assert.IsFalse(string.IsNullOrEmpty(qp["x-client-ver"])); | ||
Assert.IsFalse(string.IsNullOrEmpty(qp["x-client-cpu"])); | ||
Assert.IsFalse(string.IsNullOrEmpty(qp["x-client-os"])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like most of the validation stuff is the same in more places. ... seems duplicate and makes me think that some refactorings are needed and perhaps the tests are not testing different things... #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, i had similar feelings on copy/paste and duplication across many of the tests, this being a prime example. test cleanup and organization is also in my backlog. #Pending
// even though it's not the root cause. | ||
if (Marshal.GetExceptionCode() == 0) | ||
{ | ||
Assert.AreEqual(0, _httpMessageHandlerQueue.Count, "All mocks should have been consumed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert.AreEqual(0, _httpMessageHandlerQueue.Count, "All mocks should have been consumed"); [](start = 15, length = 91)
interesting approach,
nit as it is easy to attach a debugger...: thought perhaps list the handlers which are still in the queue... to make debugging easier? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the mocks are added in order in the tests (so it's easy to find the last one or two if they're missed), and the handlers don't "tostring" very cleanly i don't think this is worth the effort here. but let's see as we develop and if we can make improvements here we certainly will. #Closed
Is this the netcore ruleset? [mzuber] -- this is very close to the netcore ruleset but i didn't copy it from there (we definitely can do that instead). VS doesn't do quite enough yet to get code formatting consistently so I'm doing this to get some of the major cleanup points done automatically. and we can tweak the ruleset and see what we can do in plain vanilla VS so we can get more consistent here. #Pending Refers to: LibsNoSamples.sln.DotSettings:1 in e980b31. [](commit_id = e980b31, deletion_comment = False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
{ | ||
} | ||
|
||
private static bool IsMsal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think PlatformProxy does too much now. My initial refactoring idea was to break up the old "PlatformInformation" into a PlatformProxy that focuses only on OS and .net flavour (read the upn from the OS etc.) and a LibraryProxy that would handle things like "get version". #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to proceed with the current refactor since all of the code being moved in here is paltform specific. Personally, I like the idea of having some root object (like platform proxy) that gives is the central core for how we do platform disambiguation. But if we want to break this down into smaller parts hanging off platformproxy or something else, let's look into that. #Pending
… since we can't automate the browser
@@ -59,24 +60,24 @@ public AcquireTokenIWAHandler(RequestData requestData, IntegratedWindowsAuthInpu | |||
SupportADFS = true; | |||
} | |||
|
|||
this.iwaInput = iwaInput; | |||
this._iwaInput = iwaInput; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this [](start = 12, length = 4)
why do you still need this.
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.