Skip to main content

Posts

Showing posts from February, 2017

Angular 2 - Binding a promise directly to a view using AsyncPipe

Angular 2 goes reactive all the way. This means that data you get back from the http service is exposed through an observable. But how can you show the observable data on the screen? One option is to subscribe to the observable, extract the result, map it to a property on your component and databind to this property on your view. However there are better alternatives out there… Probably the cleanest solution is the use of the AsyncPipe . The main benefit to utilizing the async pipe is the performance optimization and one way data flow patterns that this feature can help enable.

Angular 2–HTTP POST is not triggered

Last week a colleague asked me for help because his HTTP POST method was not invoked inside his Angular 2 service. Here is the code he was using: this.http.post(this.apiUrl, JSON.stringify(user), this.getRequestOptions()); So why does this code doesn’t work? Reason is that the  post method of the Http class returns a cold observable. Cold observables only  are invoked when someone subscribes to it. They are kind of ‘lazy’. As we didn’t subscribe for the Observable results nothing happens.  Here is a fix: this.http.post(this.apiUrl, JSON.stringify(user), this.getRequestOptions()).subscribe(r=> {}); More information about cold vs hot observables can be found here: https://medium.com/@benlesh/hot-vs-cold-observables-f8094ed53339#.an6vzfics

ASP.NET Core: Load configuration subsection

ASP.NET Core has a lot of configuration options out of the box. One of the added possibilities is to store your configuration settings inside a JSON document. Nice advantage of using a JSON document is that you can logically group the related configuration settings in separate sections inside your document: To read values from a subsection, you specify the subsection name and the property name separated by a colon:

Angular CLI–Error when invoking ng

After installing Angular CLI and trying to invoke it using the ng command it failed with the following error message: Error while running script "C:\Users\root\AppData\Roaming\npm\node_modules\angular-cli\addon\ng2\models\config\config.ts": SyntaxError: Unexpected token ... at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.require.extensions..ts (C:\Users\root\AppData\Roaming\npm\node_modules\angular-cli\lib\bootstrap-local.js:30:14) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module._load (C:\Users\root\AppData\Roaming\npm\node_modules\angular-cli\lib\bootstrap-local.js:55:22) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (C:\Users\root\AppData\Roaming\npm\node_modules\angular-cli\addon\ng2\models\config.ts:7:16) at Module._compile (module.js:409:26) The error message itsel...

ASP.NET Core–Injecting dependencies in an MVC ActionFilter

ASP.NET Core out-of-the-box supports dependency injection on the action filter level. You have to use constructor injection to inject your dependencies in the actionfilter: However now it is no longer possible to simply add the action filter as an attribute on top of your controller or action method. This is because attributes must have their constructor parameters supplied where they are applied. Instead you have to use one of the following attributes: TypeFilterAttribute ServiceFilterAttribute The key difference is that TypeFilterAttribute will find and load the dependencies through DI, and inject them into your action filter. The ServiceFilterAttribute on the other hand attempts to find the filter from the service collection. This means that you have to register your actionfilter first:  

Help my ASP.NET Core API returns a 406 status code

Yesterday I got into trouble when invoking a specific REST API created in ASP.NET Core. Instead of getting some JSON data back from the server I got a 406 status code instead. I had no clue what was causing the issue. Luckily a colleague helped me out. I made a dumb mistake. I added the [Produces()] attribute to my Web API controller. However I accidently added an invalid content type: [Produces("listvalues/json")] instead of [Produces("application/json")] Thanks Michael for solving the problem!

Exclude properties in your Swagger OpenAPI metadata

.NET (core) has OpenAPI support through Swashbuckle , a NuGet package that generates OpenAPI metadata based on your API controllers. I was asked to manipulate the Swagger metadata to exclude a specific property from the document metadata. I found 2 possible solutions to achieve this goal: Option 1 – Add a JsonIgnore attribute on your object: Option 2 – Create a SchemaFilter: Don’t forget to register the filter in your Swagger configuration:

.NET Core compilation error: Missing compiler required member 'microsoft.csharp.runtimebinder.csharpargumentinfo.create'

After using the dynamic keyword in a .NET core test application, the project no longer compiled. Instead I got the following error message: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' The error message itself is not very helpful, but luckily the solution is easy. Just add a reference to Microsoft.CSharp.

The hardest software problem–Naming things

The hardest problem in software development is naming things. Concepts like the ubiquitous language from DDD could help but still finding the “right” name is hard! A good video about this topic is “ How to Name Things: the solution to the hardest problem in programming ” by Peter Hilton.

HTTP Security Headers

The HTTP protocol offers a lot of features to improve the security of your web app. If you have no clue what XSS, CSP, HSTS, HPKP,… means, than the following blog post is a must read: https://blog.appcanary.com/2017/http-security-headers.html It walks through a whole list of security headers explaining the use case, reasons (not) to use it, and how to activate it on your HTTP server.

Site Reliability Engineering

Interested to learn how Google runs it production systems? You should be! O’Reilly published a book created by some people of the SRE team at Google. In this book they explain how Google builds, deploys, monitor and maintain some of the largest software systems in the world. Remark: You can read the book for free online; https://landing.google.com/sre/book/index.html

whatwebcando.today: What Web Platform features are available today

While following a session about PWA(Progressive Web Apps) by a colleague, he mentioned the following website: https://whatwebcando.today . This site gives an overview of which Web Platform features are available inside your browser today and if certain HTML5 device oriented features are implemented in your browser. Thanks Mathias for the tip!

IIS - TCP Binding and multiple host headers

On one of our servers we have the following situation: We have 2 websites configured in IIS; one for development and one for internal testing. Both of these websites expose HTTP endpoints. These endpoints are using the same ports but are separated by using different host headers. The problem started to appear when we tried to do enable the TCP binding on both sites. Although we didn’t get an error message, we noticed that when we invoked our service through the TCP endpoint, we always got data back from the development environment. To fix it, we have to update our bindings in IIS. Open the IIS Manager Select the first site. Click on Bindings . Choose net.tcp binding from the list and click on Edit… Update the Binding Information from 808:* to 808:dev.sample.be Repeat the same steps for the second site but this time change the Binding Information to 808:test.sample.be

Errors in the encryption library: Failed to encrypt sensitive data.

After upgrading to SQL Server 2016 I got into trouble. As I tried to use the Analysis Services cubes I got the following error message: Errors in the encryption library: Failed to encrypt sensitive data. Possibly the encryption key is inaccessible because of improper service account change.. I was able to fix it by removing the existing datawarehouse and rebuilt the datawarehouse from scratch.

SQL Server 2016 Reporting Services - Service Unavailable

After upgrading to SQL Server 2016 I noticed that our Reporting Services website remained offline and returned a 503 Service Unavailable: A fix was already available as part of Cumulative Update 1 for SQL Server 2016: https://support.microsoft.com/en-us/help/3164674 After installing it, our Reporting Services website was back online…

Everything you need to know about Agile Development

Here is a great help in your Agile journey. DZone has grouped a lot of content to help you improve your inner Scrum Master . Here is the link: https://dzone.com/articles/stuff-every-agile-development-team-needs-to-know-a

.NET Core Roadmap

This is not the old Microsoft anymore. .NET Core is developed in the open. So if you want to know what the vision and future plans are regarding .NET Core, only one location to bookmark: https://github.com/dotnet/core/blob/master/roadmap.md So what’s coming for .NET Core 2.0: .NET Standard 2.0: Including a lot more API’s ported from the full .NET framework to .NET Core. Better tooling. Yippie! Better performance. (Although the numbers are already impressive; https://www.techempower.com/blog/2016/11/16/framework-benchmarks-round-13/ ) Better Cloud integration(of course)

The hire factor

As an application architect, making technology choices is part of the job. Each technology choice should be a balanced decision between maturity, feature richness, evolvability, support and so on… One factor that sometimes is forgotten is ‘the hire factor’. How easy is it to find people who have experience in the technology? How much like developers to work with this technology? These are important questions as most developers like new(er) technology, especially the good ones are kind of picky in their technology choices. So if you want to attract good developers, make sure that your technology landscape is attractive…