Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

[Design] Add DiagnosticSource to RazorView #6386

Merged
merged 4 commits into from
Jun 26, 2017

Conversation

jbagga
Copy link
Contributor

@jbagga jbagga commented Jun 9, 2017

Addresses #6222

cc @rynowak

@@ -46,7 +47,8 @@ public class HtmlHelper : IHtmlHelper, IViewContextAware
IModelMetadataProvider metadataProvider,
IViewBufferScope bufferScope,
HtmlEncoder htmlEncoder,
UrlEncoder urlEncoder)
UrlEncoder urlEncoder,
DiagnosticSource diagnosticSource)
Copy link
Member

Choose a reason for hiding this comment

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

@Eilon do you want this breaking change? or add a new ctor?

Choose a reason for hiding this comment

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

FWIW in other libs, we're going the clean route and changing the existing constructor since this it's a V2 release. Keep it clean since it's a good time to do so, IMO.

{
"TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper<T0> : Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper, Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<T0>",
"MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.ViewFeatures.IHtmlGenerator htmlGenerator, Microsoft.AspNetCore.Mvc.ViewEngines.ICompositeViewEngine viewEngine, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider metadataProvider, Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.IViewBufferScope bufferScope, System.Text.Encodings.Web.HtmlEncoder htmlEncoder, System.Text.Encodings.Web.UrlEncoder urlEncoder, Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ExpressionTextCache expressionTextCache)",
"Kind": "Removal"
Copy link
Member

Choose a reason for hiding this comment

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

Eilon needs to approve these btw

var adapter = new TestDiagnosticListener();

var diagnosticSource = new DiagnosticListener("Test");
diagnosticSource.SubscribeWithAdapter(adapter);
Copy link
Member

Choose a reason for hiding this comment

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

If you're not using it, you don't need this, just the new DiagnostisListener

public void PartialMethods_DoesNotWrapThrownException(
Func<IHtmlHelper, IHtmlContent> partialMethod,
object unusedModel,
ViewDataDictionary unusedViewData)
Copy link
Member

Choose a reason for hiding this comment

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

Indent is wonky here

return viewContext;
}

private class NullTempDataProvider : ITempDataProvider
Copy link
Member

Choose a reason for hiding this comment

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

Mock.Of<ITempDataProvider> would do the same thing

Html5DateRenderingMode = Html5DateRenderingMode.CurrentCulture,
ValidationSummaryMessageElement = "test",
ValidationMessageElement = "test",
TempData = new TempDataDictionary(httpContext, new NullTempDataProvider())
Copy link
Member

Choose a reason for hiding this comment

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

A lot of these things don't need to be initialized.

@@ -582,5 +618,52 @@ public override string ToString()
return "test-model-content";
}
}

internal class TestHtmlHelper : HtmlHelper
Copy link
Member

Choose a reason for hiding this comment

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

Is this the pattern that other HtmlHelper*ExtensionsTest classes follow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}
}

private ViewContext TestViewContext()
Copy link
Member

Choose a reason for hiding this comment

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

Name this like CreateViewContext()

@NickCraver
Copy link

Agree with existing notes, thanks for digging into this! I need it for MiniProfiler and haven't had the time, would love to have this fixed in 2.0.

@rynowak
Copy link
Member

rynowak commented Jun 11, 2017

would love to have this fixed in 2.0.

This is indeed planned for 2.0.0

@jbagga jbagga force-pushed the jbagga/DiagnosticsPartialViews6222 branch from 8ddc2ad to 59180ff Compare June 12, 2017 22:18
@jbagga
Copy link
Contributor Author

jbagga commented Jun 12, 2017

@rynowak Updated

@jbagga jbagga force-pushed the jbagga/DiagnosticsPartialViews6222 branch from 59180ff to 7a1e91c Compare June 12, 2017 22:28
@jbagga jbagga force-pushed the jbagga/DiagnosticsPartialViews6222 branch from 7a1e91c to b6a122e Compare June 23, 2017 21:51
@jbagga
Copy link
Contributor Author

jbagga commented Jun 23, 2017

@rynowak Updated. Changed the initial design

@jbagga jbagga changed the title Add DiagnosticSource to HtmlHelper [Design] Add DiagnosticSource to HtmlHelper Jun 23, 2017
{
diagnosticSource.Write(
"Microsoft.AspNetCore.Mvc.Razor.BeforeRazorView",
new { page = page, viewContext = viewContext, });
Copy link
Member

Choose a reason for hiding this comment

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

include the action descriptor and http context with the same names as every other event. yes it's redundant and we do that on purpose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to make it consistent with BeforeView and AfterView here.

Should these also include the ActionDescriptor and HttpContext?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the viewcontext gets you access to the two.

Copy link
Member

Choose a reason for hiding this comment

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

No, the viewcontext gets you access to the two.

yes it's redundant and we do that on purpose

YES THESE NEED TO INCLUDE THE ACTION DESCRIPTOR AND HTTP CONTEXT.

We do that on purpose so that you don't have to maintain a million proxies.

If another event is missing those fields, they should be added.

_pageActivator.Activate(page, context);

_diagnosticSource.AfterRazorView(page, context);
Copy link
Member

Choose a reason for hiding this comment

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

This isn't right. You need to add a try/finally around L175 and surround that

Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

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

asdf

@jbagga jbagga changed the title [Design] Add DiagnosticSource to HtmlHelper [Design] Add DiagnosticSource to RazorView Jun 26, 2017
{
diagnosticSource.Write(
"Microsoft.AspNetCore.Mvc.Razor.BeforeRazorView",
new { page = page, viewContext = viewContext, });
Copy link
Contributor

Choose a reason for hiding this comment

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

No, the viewcontext gets you access to the two.

@@ -155,7 +165,13 @@ public class RazorView : IView
private Task RenderPageCoreAsync(IRazorPage page, ViewContext context)
{
page.ViewContext = context;

_diagnosticSource.BeforeRazorView(page, context);
Copy link
Contributor

Choose a reason for hiding this comment

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

The methods should probably be named BeforeRazorPage \ AfterRazorPage since they're logging individual page execution.

@jbagga jbagga force-pushed the jbagga/DiagnosticsPartialViews6222 branch from b6a122e to 6bc17c5 Compare June 26, 2017 18:18
@jbagga
Copy link
Contributor Author

jbagga commented Jun 26, 2017

@rynowak @pranavkm Updated

IRazorPage page,
ViewContext viewContext)
{
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.AfterRazorView"))
Copy link
Member

Choose a reason for hiding this comment

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

Is it page or view? the method says page, but the event says view

{
return page.ExecuteAsync();
}

Copy link
Member

Choose a reason for hiding this comment

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

Blank line police


try
{
return page.ExecuteAsync();
Copy link
Member

Choose a reason for hiding this comment

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

This isn't valid, this needs to be an await

@jbagga
Copy link
Contributor Author

jbagga commented Jun 26, 2017

@rynowak Updated

@jbagga jbagga merged commit f4a86f5 into dev Jun 26, 2017
@jbagga jbagga deleted the jbagga/DiagnosticsPartialViews6222 branch June 26, 2017 22:36
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.

5 participants