Skip to content

Commit 0c4d1ec

Browse files
authored
Merge pull request #114 from FritzAndFriends/dev
Cleanup code
2 parents 43e43f7 + 4a8a30d commit 0c4d1ec

File tree

61 files changed

+882
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+882
-214
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ csharp_style_var_for_built_in_types = true:error
1212
csharp_style_var_when_type_is_apparent = true:error
1313
csharp_style_var_elsewhere = true:error
1414
csharp_prefer_braces = true
15+
16+
# Remove compiler warnings
17+
dotnet_diagnostic.CS0618.severity = none ## Obsolete warning
18+
dotnet_diagnostic.CS1591.severity = none ## XML Documentation warning
19+
dotnet_diagnostic.CS1574.severity = none ## XML Documentation reference warning

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*.sln.docstates
1111
*.ncrunchproject
1212
*.ncrunchsolution
13+
*.swp
1314

1415
# Project XML documentation
1516
BlazorWebFormsComponents.xml
@@ -339,4 +340,4 @@ ASALocalRun/
339340
# macOS
340341
.DS_Store
341342
.AppleDouble
342-
.LSOverride
343+
.LSOverride

BlazorMeetsWebForms.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionInfo", "SolutionInf
3838
version.json = version.json
3939
EndProjectSection
4040
EndProject
41+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "watch", "watch", "{A4769DEE-1006-4D87-B20E-E875C556B3E8}"
42+
ProjectSection(SolutionItems) = preProject
43+
scripts\watch.csproj = scripts\watch.csproj
44+
scripts\watchtest = scripts\watchtest
45+
EndProjectSection
46+
EndProject
4147
Global
4248
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4349
Debug|Any CPU = Debug|Any CPU

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ We believe that Web Forms applications that have been well maintained and provid
1212

1313
This is not for everyone, not everyone needs to migrate their application. They can continue being supported as Web Forms for a very long time (2029 EOL at the time of this writing) and the applications that are considered for migration to Blazor may be better suited with a complete re-write. For those applications that need to be migrated, this library should help make that process simpler by providing components with the same names, markup, and functionality as previously available.
1414

15-
[Strategies for your migration and steps ahead](docs/Migration/README.md) are available as part of this repository.
15+
[Get started with your migration, steps ahead, and strategy documentation](docs/Migration/readme.md) for various controls and tools used are available.
1616

1717
Portions of the [original .NET Framework](https://github.com/microsoft/referencesource) are contributed to this project under their MIT license.
1818

@@ -52,9 +52,10 @@ We will NOT be converting any DataSource objects, Wizard components, skins or th
5252

5353
## Utility Features
5454

55-
There are a handful of features that augment the ASP<span></span>.NET development experience that are made available as part of this project in order to support migration efforts. These features include:
55+
There are a handful of features that augment the ASP<span></span>.NET development experience that are made available as part of this project in order to support migration efforts. Importantly, these features are NOT implemented the same way that they are in Web Forms, but rather have the same API and behave in a proper Blazor fashion. These features include:
5656

5757
- [DataBinder](docs/Databinder.md)
58+
- [ViewState](docs/ViewState.md)
5859

5960
## Compiling the project
6061

docs/Migration/Custom-Controls.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Custom Controls Migration Strategy
2+
3+
>> Content to come!

docs/Migration/MasterPages.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# MasterPages
2+
3+
>> Content to come!

docs/Migration/NET-Standard.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# .NET Standard to the Rescue
2+
3+
.NET Standard is the definition of a contract, a series of APIs, that all .NET frameworks must implement to be considered a .NET framework. .NET Framework, .NET Core, Xamarin, and Mono all implement various .NET Standard versions (or specifications) and this now becomes a vehicle for you to build your class libraries to be re-usable across various version of .NET.
4+
5+
>> Needs links to the .NET Standard specifications and repository on GitHub
6+
7+
Class libraries can be built and target different version specifications of .NET Standard. You can target _ANY_ version of .NET Standard and gain compatibility across .NET Framework and .NET Core, but we recommend you target at least _.NET Standard 2.0_
8+
9+
>> Add image showing compatibility table of .NET Standard
10+
11+
## Implications
12+
13+
For your existing Web Forms applications, unless you are executing unsafe code or p-invoking methods, you should be able to migrate much of your application's business logic to a .NET Standard targeting class library. This has several benefits:
14+
15+
1. You can migrate your business logic to the .NET Standard class library project, reference that project, and continue to use that logic in your ASP<span></span>.NET Web Forms application.
16+
1. Your new .NET Standard class library project can be _DIRECTLY_ referenced by your migrated ASP<span></span>.NET Core / Server-side Blazor application
17+
1. Your business logic code is now isolated from your presentation code, and should be more testable. Write some unit tests to verify that your business logic is behaving properly.
18+
1. If you'd like to write a mobile application to work with your web application, you can re-use your .NET Standard project with the Xamarin frameworks.
19+
20+
## Sample 1: Update an existing class library
21+
22+
The first sample demonstrates updating a simple class library to .NET Standard. In this model, we're assuming that you already have your business logic code properly separated from your user-interface and managed inside a class-library project that targets .NET Framework 4.5. You can find the source and directions for this sample in the [samples/netstandard-1](samples/netstandard-1) folder.
23+
24+
## Sample 2: Refactoring Business Logic
25+
26+
The second sample shows how to take an existing ASP<span></span>.NET application and refactor our some business logic as a .NET Standard project. You can find the source and directions for this sample in the [samples/netstandard-2](samples/netstandard-2) folder.

docs/Migration/README.md renamed to docs/Migration/Strategies.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Migration from ASP<span></span>.NET Web Forms to Blazor is not simple and this r
44

55
We, the maintainers of this project, believe that with a little ingenuity the markup from a Web Forms application can be copied over with minimal changes and function similarly to its original purpose. We believe that well formatted and maintained code in Web Forms should be easily migrated. Applications that are a significant mix of C# and markup will have a more difficult time going through this process.
66

7+
## Readiness Planning
8+
9+
Migrating an application to Blazor is not a trivial process and it would be great to have some indication ahead of time how much work is needed and what steps you need to take to prepare to migrate. Check our migration [readiness document](../migration_readiness.md) to help determine how much work will be needed for your application to begin the process.
10+
711
## Known Required Changes
812

913
There are several changes that are going to need to be made to the markup in your ASPX and ASCX files in order to get them working. Some of these are obvious changes, and some are considerations necessary for the razor templating and Blazor rendering engine.
@@ -26,23 +30,45 @@ Components are the building blocks for Blazor, just as controls were in Web Form
2630

2731
### MasterPages are no more
2832

29-
The concept of a MasterPage does not exist in Blazor. Instead, your ASPX pages will be loaded inside of a host page. You can compose a razor component that hosts other *converted ASPX pages* but your pages cannot dictate their parent container. See the MasterPage strategy below for more details.
33+
The concept of a MasterPage does not exist in Blazor. Instead, your ASPX pages will be loaded inside of a host page. You can compose a razor component that hosts other *converted ASPX pages* but your pages cannot dictate their parent container. See the [MasterPage strategy](MasterPages.md) below for more details.
3034

3135
### Page Directive Changes
3236

37+
### No <%#: DataBinding expressions
38+
39+
Databinding expressions in Web Forms let you evaluate the content of the elements and format them appropriately for presentation. For editor controls, it also allows you to setup a 2-way binding so that you can receive values entered into the same variable bound to the control.
40+
41+
In Blazor, for repeater-style components, just format the variable using context, Item, and simple formatting like this:
42+
43+
```csharp
44+
@Item.ShipDate.ToString("D")
45+
```
46+
47+
For editor components, simply `@bind` the variable to the component. This will give you two-way data-binding and the ability to handle changes in the editor component AS it changes.
48+
49+
```html
50+
<input type="text" name="foo" @bind="bar" />
51+
```
52+
3353
### No Namespaces, No Tag-Prefixes
3454

35-
Namespaces and tag-prefixes are gone. You can do a Find and Replace on asp: and remove those from your markup.
55+
Namespaces and tag-prefixes are gone. You can do a Find and Replace on `asp:` and remove those from your markup.
56+
57+
### Redirect Color to WebColor
58+
59+
This change should **NOT** require any coding modifications. In Web Forms, you could refer to `System.Drawing.Color` objects when setting `BackColor`, `BorderColor`, and `ForeColor` to name a few properties. You could _ALSO_ freely use HTML hex-color notation freely in these fields.
60+
The `System.Drawing.Color` object does not have a converter that allows you to convert between these two formats, so we wrapped the object and made `BlazorWebFormsComponents.WebColor` that performs the same task and allows the interchange of `System.Drawing.Color` object with HTML hex notation.
3661

3762
## Strategies
3863

3964
- A simple initial site migration
4065
- Intertwined code
4166
- [DataBinder](Databinder.md)
4267
- Model-Binding
43-
- .NET Standard to the rescue!
68+
- [.NET Standard to the rescue!](NET-Standard.md)
4469
- Other considerations
45-
- MasterPage
70+
- [MasterPage](MasterPages.md)
4671
- Rearchitecting Web Application Layout
4772
- UserControls
4873
- The simple conversion
74+
- [Custom Controls](Custom-Controls.md)

docs/Migration/User-Controls.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# User Controls
2+
3+
>> Content to come
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Web Forms Application Migration Readiness
2+
3+
This document is intended as a primer for prospective teams to review in preparation for migrating their Web Forms applications to Server-Side Blazor. We believe the migration is a multi-step process and this application review and preparation is the first step in migrating / rewriting an application using Blazor.
4+
5+
## Definitions
6+
7+
Throughout this document, we will refer to several framework and technology terms. This section will clarify those terms.
8+
9+
- **Web Forms**
10+
- The ASP<span></span>.NET user-interface technology that started with the release in 2002 and is typically identified by applications with web pages that have a `.ASPX` file-extension
11+
- **MVC**
12+
- Model-View-Controller architecture introduced in 2009 as an alternative user-interface framework for ASP<span></span>.NET developers. A project structure that uses the MVC framework typically has 3 or 4 folders in it named `Areas`, `Models`, `Views`, `Controllers`
13+
- **Razor Views**
14+
- The template technology uses by modern ASP<span></span>.NET MVC and ASP<span></span>.NET Core applications. Typically, these files are found in the `Views` folder and have a `.cshtml` file-extension
15+
16+
## High-Level Requirements
17+
18+
- ASPX in-line Visual Basic not supported on Razor components in .NET Core
19+
- Convert to C# or move out to a class library
20+
- No data source controls on ASPX pages
21+
- Business logic needs to be convertible to .NET Core
22+
- Class libraries referenced need to be convertible to .NET Standard
23+
- No 3rd party control libraries that don't have a shim for conversion (none available at the time of this writing)
24+
25+
## Application architecture suggestions
26+
27+
- Prefer model-binding techniques over handling Form life-cycle events like `Init`, `Load`, `PreRender`, and `Unload`
28+
- These event-handlers do not exist and function the same way in Blazor. Avoid acting outside of the `Load` event. The actions you are taking in `Load` can be executed at the conclusion of the `Initialize` event in Blazor
29+
- Use a repository pattern with interfaces declared for the repositories
30+
- Inject the concrete implementation of the data access technology. It _MAY_ change to HTTP access at some point in the future
31+
- Minimal code embedded in ASPX files - this code will need to be updated to work with the components, where they were using full-featured controls.
32+
- No calls through the control hierarchy. E.g. `FindControl()`
33+
- Any hybrid applications that contains both MVC and Web Forms user interface content will take some extra work to be converted, as the MVC components will need to be converted to ASP<span></span>.NET Core
34+
- `System.Confuguration.ConfigurationManager` access will need to be rewritten to use `Microsoft.Extensions.Configuration.IConfiguration` objects that are injected
35+
- Push configuration access to a repository class object that can be migrated to the new Configuration model in .NET Core
36+
- `HttpContext.Current` access will need to be reevaluated. Direct `HttpContext` access should be avoided in Blazor
37+
- Custom components will need to be rewritten
38+
- User controls `.ASCX` files should be converted to Blazor components
39+
- HttpHandlers and HttpModules will need to be rewritten as ASP<span></span>.NET Core middleware
40+
- MasterPages can be converted to Layout components
41+
- Mobile device detection is not available as part of Blazor. `Site.mobile.master` will not be directly used by the framework.
42+
- Instead of using an alternate rendering strategy for mobile, we recommend you embrace an adaptive rendering strategy to ensure that mobile device visitors to your application get a good experience

0 commit comments

Comments
 (0)