Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Aug 5, 2020
2 parents 4e3ed5f + 4665dbd commit 51f97b0
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<ol>
<li>MyClass is not the owner of the RSA instance. It didn't create it and therefore shouldn't dispose it.</li>
<li>The RSA instance could have been injected somewhere else as well, therefore disposing it would cause a bug.</li>
<li>There is a <a href="http://dailydotnettips.com/2014/01/15/benefit-of-using-in-dispose-for-net-objects-why-and-when/">benefit of the using statement</a> and the constructor injection pattern doesn't allow me to make use of it</li>
<li>There is a <a href="http://dailydotnettips.com/benefit-of-using-in-dispose-for-net-objects-why-and-when/">benefit of the using statement</a> and the constructor injection pattern doesn't allow me to make use of it</li>
</ol>
<p>This means we are better off by using a different dependency injection pattern. In this instance the factory pattern is more suitable:</p>
<pre><code>public interface IRSAFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<h2>Scrumban</h2>

<p>While Scrum is a continuous sequence of time boxed iterations, Kanban has only one continuous flow. The repetition of process establishes routine and familarity. A well accustomed team could struggle to adopt Kanban and give up the routine.</p>
<p>This is where <a href="http://leansoftwareengineering.com/ksse/scrum-ban/">Scrumban</a> comes into play, initially invented to help teams with the transition from Scrum to Kanban. In Scrumban a team primarily uses Scrum as their chosen way of work and mixes in concepts from Kanban to allow for specialised roles, work policies and a better flow.</p>
<p>This is where <a href="https://www.agilealliance.org/what-is-scrumban/">Scrumban</a> comes into play, initially invented to help teams with the transition from Scrum to Kanban. In Scrumban a team primarily uses Scrum as their chosen way of work and mixes in concepts from Kanban to allow for specialised roles, work policies and a better flow.</p>
<p>One fundamental idea of Scrumban is to help teams and organizations develop their own set of Scrum-based processes and practices that work best for them.</p>

<h2>Which process will you pick?</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ If you have worked with [Swagger](http://swagger.io/) or [API Blueprint](https:/

At the time of writing there are two public specifications:

- [RAML 0.8](https://github.com/raml-org/raml-spec/blob/master/raml-0.8.md)
- [RAML 1.0 RC](http://docs.raml.org/specs/1.0/)
- [RAML 0.8](https://github.com/raml-org/raml-spec/blob/master/versions/raml-08/raml-08.md)
- [RAML 1.0 RC](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/)

In this blog post I will be using RAML 0.8 and assume that you are familiar enough with the spec to follow my simple examples as part of the demo.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The question is what shall we do with dependencies which implement `IDisposable`

## How to manage a dependency which implements IDisposable?

The intentions were definitely good. The repository implements `IDisposable` obviously for a good reason. `IDisposable` is usually used [when a class has some expensive or unmanaged resources](https://msdn.microsoft.com/en-us/library/system.idisposable) allocated which need to be released after their usage. Not disposing an object can lead to memory leaks. In fact it is so important that the C# language offers the [using](https://msdn.microsoft.com/en-us/library/yh598w02.aspx?f=255&MSPPError=-2147217396) keyword to minimize risk of not cleaning up resources in certain edge cases such as the occurence of an exception. Generally it should be a red flag if an instance of `IDisposable` has not been wrapped in a `using` block, which is another good indicator that the code from above has a fundamental problem. I am actually surprised that no one at Microsoft picked this up before publishing the [article on the UnitOfWork](http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application) pattern.
The intentions were definitely good. The repository implements `IDisposable` obviously for a good reason. `IDisposable` is usually used [when a class has some expensive or unmanaged resources](https://msdn.microsoft.com/en-us/library/system.idisposable) allocated which need to be released after their usage. Not disposing an object can lead to memory leaks. In fact it is so important that the C# language offers the [using](https://msdn.microsoft.com/en-us/library/yh598w02.aspx?f=255&MSPPError=-2147217396) keyword to minimize risk of not cleaning up resources in certain edge cases such as the occurrence of an exception. Generally it should be a red flag if an instance of `IDisposable` has not been wrapped in a `using` block, which is another good indicator that the code from above has a fundamental problem. I am actually surprised that no one at Microsoft picked this up before publishing the [article on the UnitOfWork](http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application) pattern.

In most cases the creator of an object will be the IoC container. Therefore it should be the IoC container's responsibility to dispose an object after its usage, except that this is very difficult at this stage of an application. Either the object will live too long or too short which brings us back to the initial problem.

Expand Down Expand Up @@ -82,14 +82,14 @@ public class MyClass
}
}</code></pre>

The constructor parameter has been changed from an `IRepository` to an `IRepositoryFactory`. The instantiation of the repository has been deferred to the the actual time of usage and the `Dispose()` method has been made redundant. Additionally I was able to benefit from the `using` keyword and overall reduce the total amount of code. This solution is much more elegant, more robust and free of the initial error.
The constructor parameter has been changed from an `IRepository` to an `IRepositoryFactory`. The instantiation of the repository has been deferred to the actual time of usage and the `Dispose()` method has been made redundant. Additionally I was able to benefit from the `using` keyword and overall reduce the total amount of code. This solution is much more elegant, more robust and free of the initial error.

The big difference is that `MyClass` takes care of creating a repository now. Per definition a factory always creates a new instance, so there is no ambiguity about the object's lifespan. In terms of testability and extensibility nothing has really changed. The factory gets injected through the constructor which makes it easily exchangable with another implementation or a mock in tests.
The big difference is that `MyClass` takes care of creating a repository now. Per definition a factory always creates a new instance, so there is no ambiguity about the object's lifespan. In terms of testability and extensibility nothing has really changed. The factory gets injected through the constructor which makes it easily exchangeable with another implementation or a mock in tests.

## Dependency injection is not always the best option

This is a great example where dependency injection is not always the best suited IoC pattern. [Dependency injection in all three forms](https://en.wikipedia.org/wiki/Dependency_injection#Three_types_of_dependency_injection) (constructor, property and method injection) is only one of many possible ways of the [dependency inversion principle](https://en.wikipedia.org/wiki/Dependency_inversion_principle). Factories and other [creational design patterns](https://en.wikipedia.org/wiki/Creational_pattern) are still useful and have their place in modern software architecture.

Subtle differences like the one from above can determine wether you have a severe bug in your application or not. Sometimes it is not even a question of stylistic preference.
Subtle differences like the one from above can determine whether you have a severe bug in your application or not. Sometimes it is not even a question of stylistic preference.

Another good read on the proper use of the `IDisposable` interface is [this amazing StackOverflow answer](http://stackoverflow.com/questions/538060/proper-use-of-the-idisposable-interface#answer-538238) by [Ian Boyd](http://stackoverflow.com/users/12597/ian-boyd).
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ However, when I started to migrate from C# to NancyFx and F# I had quite some di

As I said before, some of the stuff is **really simple** and probably super easy for an experienced F# developer, but for me as a beginner it was not that obvious in the beginning.

A great start on NancyFx and F# is [Michal Franc's blog post](http://www.mfranc.com/blog/f-and-nancy-beyond-hello-world/), where he shows how to register a normal route in NancyFx with F#:
A great start on NancyFx and F# is [Michal Franc's blog post](https://mfranc.com/f/f-and-nancy-beyond-hello-world/), where he shows how to register a normal route in NancyFx with F#:

<pre><code>type MyModule() as this =
inherit NancyModule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ On the third step there's a bunch of information available, but luckily the defa

<img src="https://storage.googleapis.com/dusted-codes/images/blog-posts/2016-05-01/26141065614_171cd62fa3_o.png" alt="aws-ec2-instance-advanced-details, Image by Dustin Moris Gorski" class="half-width">

You will be presented with a text field which can be used to specify additional commands which will run when launching the new EC2 instance. We will add a few commands which will automatically install and configure the [Tinyproxy](https://tinyproxy.github.io/) software. Tinyproxy is a [free and open source proxy server](https://en.wikipedia.org/wiki/Tinyproxy) for POSIX operating systems.
You will be presented with a text field which can be used to specify additional commands which will run when launching the new EC2 instance. We will add a few commands which will automatically install and configure the [Tinyproxy](https://tinyproxy.github.io/) software. Tinyproxy is a [free and open source proxy server](https://github.com/tinyproxy/tinyproxy) for POSIX operating systems.

Copy the following code snippet into the text field:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ You can always open a JMeter results file with one of the existing listeners fro

If you want to analyse and evaluate your results from an automated build then you will have to do some more scripting. It mostly depends what type of analysis you would like to perform, but in most cases you will be able to extract the relevant information with only a few simple commands.

For that purpose you could use PowerShell as the native language on Windows machines or if you are looking for something more portable then you could write a small C# or F# library, which can be either invoked directly from tools like [CAKE](http://cakebuild.net/), [FAKE](http://fsharp.github.io/FAKE/), the [FSI](https://msdn.microsoft.com/en-us/visualfsharpdocs/conceptual/fsharp-interactive-%5Bfsi.exe%5D-reference) or from a console application build on Mono. Just to give you a taster of how simple that can be you an check out [this small F# application](https://github.com/dustinmoris/JMeterResultsAnalyser).
For that purpose you could use PowerShell as the native language on Windows machines or if you are looking for something more portable then you could write a small C# or F# library, which can be either invoked directly from tools like [CAKE](http://cakebuild.net/), [FAKE](http://fsharp.github.io/FAKE/), the [FSI](https://docs.microsoft.com/en-us/dotnet/fsharp/tutorials/fsharp-interactive/) or from a console application build on Mono. Just to give you a taster of how simple that can be you an check out [this small F# application](https://github.com/dustinmoris/JMeterResultsAnalyser).

## BlazeMeter for everyone

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Here's a list of a some of the many awesome things that happened at Microsoft in
- [Visual Studio Code, an open source free IDE for Windows, Mac and Linux](http://www.hanselman.com/blog/IntroducingVisualStudioCodeForWindowsMacAndLinux.aspx)
- [PowerShell became open source and available on Linux](http://open.microsoft.com/2016/08/19/powershell-is-open-sourced-and-available-on-linux/)
- [Microsoft made SQL Server available on Linux](https://techcrunch.com/2016/03/07/microsoft-is-bringing-sql-server-to-linux/)
- [Microsoft joined the Linux Foundation](https://www.linuxfoundation.org/announcements/microsoft-fortifies-commitment-to-open-source-becomes-linux-foundation-platinum)
- [Microsoft joined the Linux Foundation](https://www.linuxfoundation.org/press-release/2016/11/microsoft-fortifies-commitment-to-open-source-becomes-linux-foundation-platinum-member/)
- [Microsoft even offers certification for Linux on Azure](http://news.microsoft.com/2015/12/09/microsoft-offers-new-certification-for-linux-on-azure/#hdYyJXK4A7pp2Eh2.97)
- [Microsoft acquired Xamarin](http://blogs.microsoft.com/blog/2016/02/24/microsoft-to-acquire-xamarin-and-empower-more-developers-to-build-apps-on-any-device/)
- [Two months later Microsoft open sourced Xamarin's SDK](http://www.zdnet.com/article/microsoft-open-sources-xamarins-software-development-kit/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Everything should compile successfully and you should see a Hello-World Giraffe

<h2 id="nested-routing">Nested routing</h2>

Another cool feature which has been added by [Stuart Lang](slang25) is nested routing.
Another cool feature which has been added by [Stuart Lang](https://twitter.com/stuartblang) is nested routing.

The new `subRoute` handler allows users to create nested routes which can be very useful when logically grouping certain paths.

Expand All @@ -90,7 +90,7 @@ There is also a [`subRouteCi`](https://github.com/dustinmoris/Giraffe#subrouteci

<h2 id="razor-views">Razor views</h2>

Next is the support of Razor views in Giraffe. [Nicol&aacute;s Herrera](https://github.com/nicolocodev) developed the first version of Razor views by utilising the [RazorLight](https://github.com/toddams/RazorLight) engine. Shortly after that I realised that by referencing the `Microsoft.AspNetCore.Mvc` NuGet package I can easily re-use the original Razor engine in order to offer a more complete and original Razor experience in Giraffe as well. While under the hood the engine changed from [RazorLight](https://www.nuget.org/packages/RazorLight/) to [ASP.NET Core MVC](https://github.com/aspnet/Mvc/tree/dev/src/Microsoft.AspNetCore.Mvc.Razor) the functionality remained more or less the same as implemented by Nicol&aacute;s in the first place.
Next is the support of Razor views in Giraffe. [Nicol&aacute;s Herrera](https://github.com/nicolocodev) developed the first version of Razor views by utilising the [RazorLight](https://github.com/toddams/RazorLight) engine. Shortly after that I realised that by referencing the `Microsoft.AspNetCore.Mvc` NuGet package I can easily re-use the original Razor engine in order to offer a more complete and original Razor experience in Giraffe as well. While under the hood the engine changed from [RazorLight](https://www.nuget.org/packages/RazorLight/) to [ASP.NET Core MVC](https://github.com/dotnet/aspnetcore) the functionality remained more or less the same as implemented by Nicol&aacute;s in the first place.

In order to enable Razor views in Giraffe you have to register it's dependencies first:

Expand Down Expand Up @@ -123,7 +123,7 @@ let app =
route "/" >=> razorHtmlView "Index" model
]</code></pre>

A more involved example with a layout page and a partial view can be found in the [SampleApp](https://github.com/dustinmoris/Giraffe/tree/develop/samples/SampleApp/SampleApp/views) project in the [Giraffe repository](https://github.com/dustinmoris/Giraffe).
A more involved example with a layout page and a partial view can be found in the [SampleApp](https://github.com/giraffe-fsharp/samples/blob/master/demo-apps/SampleApp/SampleApp/HtmlViews.fs) project in the [Giraffe samples repository](https://github.com/giraffe-fsharp/samples).

### Using DotNet Watcher to reload the project on Razor page changes

Expand Down Expand Up @@ -163,7 +163,7 @@ For me it's really about making smart choices and I truly believe that the stren

<h2 id="functional-html-view-engine">Functional HTML view engine</h2>

Speaking of the Razor view engine, another really cool feature which has been added to Giraffe is a new programmatic way of creating views. [Florian Verdonck](https://github.com/nojaf) helped me a lot with Giraffe over the last few weeks and one of his contributions was to port [Suave's experimental Html engine](https://github.com/SuaveIO/suave/blob/master/src/Experimental/Html.fs) to Giraffe.
Speaking of the Razor view engine, another really cool feature which has been added to Giraffe is a new programmatic way of creating views. [Florian Verdonck](https://github.com/nojaf) helped me a lot with Giraffe over the last few weeks and one of his contributions was to port [Suave's experimental Html engine](https://github.com/SuaveIO/suave/blob/master/src/Suave.Experimental/Html.fs) to Giraffe.

I think the best way to describe the new `Giraffe.HtmlEngine` is by showing some code:

Expand Down
2 changes: 1 addition & 1 deletion src/DustedCodes/BlogPosts/2017_08_12-giraffe-goes-beta.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ After 6 months of working on [Giraffe](https://github.com/dustinmoris/Giraffe),

### XmlViewEngine

Since the last blog post I have made several improvements to the previously known [functional HTML engine](https://dusted.codes/functional-aspnet-core-part-2-hello-world-from-giraffe#functional-html-view-engine), which has been renamed to a more generic [XmlViewEngine](https://github.com/dustinmoris/Giraffe#renderhtml) now. The new changes allow the `XmlViewEngine` to be used beyond simple HTML views and can be used for things like generating dynamic XML such as [SVG images](https://github.com/dustinmoris/CI-BuildStats/blob/master/src/BuildStats/Views.fs) and more. Personally I think the [XmlViewEngine](https://github.com/dustinmoris/Giraffe/blob/master/src/Giraffe/XmlViewEngine.fs) is the most feature rich and powerful view engine you can find in any .NET framework today and I will certainly dedicate a whole separate blog post on that topic alone in the near future soon.
Since the last blog post I have made several improvements to the previously known [functional HTML engine](https://dusted.codes/functional-aspnet-core-part-2-hello-world-from-giraffe#functional-html-view-engine), which has been renamed to a more generic [XmlViewEngine](https://github.com/dustinmoris/Giraffe#renderhtml) now. The new changes allow the `XmlViewEngine` to be used beyond simple HTML views and can be used for things like generating dynamic XML such as [SVG images](https://github.com/dustinmoris/CI-BuildStats/blob/master/src/BuildStats/Views.fs) and more. Personally I think the [XmlViewEngine](https://github.com/dustinmoris/Giraffe/blob/v0.1.0-beta-001/src/Giraffe/XmlViewEngine.fs) is the most feature rich and powerful view engine you can find in any .NET framework today and I will certainly dedicate a whole separate blog post on that topic alone in the near future soon.

### Continuations instead of bindings

Expand Down
Loading

0 comments on commit 51f97b0

Please sign in to comment.