Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Refactor http to reduce static singleton dependencies #1310

Merged
merged 20 commits into from
Oct 17, 2018
Merged

Conversation

MarkZuber
Copy link
Contributor

@MarkZuber MarkZuber commented Oct 9, 2018

No description provided.

public ICryptographyManager CreateCryptographyManager()
{
return new iOSCryptographyManager();
}
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

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

@henrik-me
Copy link
Contributor

henrik-me commented Oct 10, 2018

Looks great! Added a few points... most of them probably just for a quick chat. #Closed

}
//interface IHttpClientFactory
//{
// IHttpClient Create(string uri, RequestContext requestContext);
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove completely? #Closed

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed #Closed

#elif IS_MSAL
return true;
#else
return true; // TODO: should we default to MSAL or should we default to throw exception?
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed #Closed


ILegacyCachePersistance CreateLegacyCachePersistence();
ITokenCacheAccessor CreateTokenCacheAccessor();
ICryptographyManager CreateCryptographyManager();
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

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

@henrik-me
Copy link
Contributor

henrik-me commented Oct 10, 2018

            return version[1];

Outside the scope of the refactoring,,, but considering introducing caching here... using well, a static given the class is static.
perhaps it would be worth caching this value? no need for every telemetry entry to re-calculate this value.
thoughts?

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>
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

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;
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

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();
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

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
//{
//}
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove completely ? #Closed

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed #Closed

@henrik-me
Copy link
Contributor

henrik-me commented Oct 10, 2018

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"]));
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

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");
Copy link
Contributor

@henrik-me henrik-me Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

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

@henrik-me
Copy link
Contributor

henrik-me commented Oct 10, 2018

<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

Is this the netcore ruleset?
Should we have the same for the one with samples? .... would have liked the same for vs settings... as I do not currently use resharper.

[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)

Copy link
Contributor

@henrik-me henrik-me left a 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()
Copy link
Member

@bgavrilMS bgavrilMS Oct 10, 2018

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

Copy link
Contributor Author

@MarkZuber MarkZuber Oct 10, 2018

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

@@ -59,24 +60,24 @@ public AcquireTokenIWAHandler(RequestData requestData, IntegratedWindowsAuthInpu
SupportADFS = true;
}

this.iwaInput = iwaInput;
this._iwaInput = iwaInput;
Copy link
Contributor

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?

Copy link
Contributor

@henrik-me henrik-me left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@MarkZuber MarkZuber merged commit 93d88f3 into dev Oct 17, 2018
@MarkZuber MarkZuber deleted the markzuber/http branch October 17, 2018 18:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants