How to exclude Json properties from WebApi response using a custom ContractResolver

I am currently working on a Backend API that acts as a middleman to a Front API and a DocumentDB database (the structure is shown in the above image).

 

I had the following class which is used to send data to both the Front API and to the DocumentDB. Some of the fields needed to be hidden when returning a response back to the Front API, since they weren’t useful for the user and for security concerns. First I tried using [JsonIgnore] and [IgnoreDataMember] (as seen below), which successfully excluded the required fields from the response, but using them was also excluding the same fields when sending the data to DocumentDB, so it was a no-go. Continue reading

The correct way to implement StructureMap in .NET Core WebApi when having multiple projects

StructureMap is an IoC/DI container for .Net which has been a long time around. I’ve been using it for these past few years, and after all this time, I found out the correct way to implement it.

This is how I used it before and I’m sure the majority of you are currently using the same methods. In the Registry, I would register each interface and it’s inherited class by calling a “config.for” for each service as follows:

    config.For(typeof(ITestService)).Add(typeof(TestService));
    config.For(typeof(IUserService)).Add(typeof(UserService));
    config.For(typeof(ITenantService)).Add(typeof(TenantService));
    config.For(typeof(IProjectService)).Add(typeof(ProjectService));

And whenever new interfaces and services are added, they need to be registered using a new “config.for” line.

That was the old way, of how I did things. This is the new way. Continue reading

Unlock and Access your blocked Files

unlocker-icon-windows-7

Have you ever experienced any of the following annoying messages when using Windows:

  • Cannot delete file: Access is denied.
  • There has been a sharing violation.
  • The source or destination file may be in use.
  • Make sure the disk is not full or write-protected and that the file is not currently in use.

Or did you ever wanted to open Outlook and instead of the Inbox you are shown the ‘The file is in use and cannot be accessed’ popup?

Outlook-Data-File-3

This happened to me several times, and the only way I could solve it was to restart my computer to unblock my outlook file (or any other files blocked), until I found this solution. Continue reading

Stop Auto-Resolving Tasks in TFS #VisualStudio

Microsoft-Visual-Studio-icon

When checking-in pending updates to tasks in TFS, Team Explorer usually sets the task as ‘Resolve’ by default. But sometimes you just need to check in part of the updates, and set the update as ‘Associate’. To stop Team Explorer from auto-resolving your task on check-in, you need to follow the next steps:

For Visual Studio 2013

  • Go to: Start -› RegEdit
  • Find Key: [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\TeamFoundation\SourceControl\Behavior]
  • Update Value: “ResolveAsDefaultCheckinAction”=”False”

For Visual Studio 2015

  • Go to: Visual Studio -› Tools -› Options -› Source Control

Now let’s continue those tasks!

& Thanks to Masu for the enlightenment 🙂

SharePoint Keeps Refreshing #QuickSolution

This week I had an issue with SharePoint. I tried to log in to our work’s SharePoint account to add a new blog post about Email Management. But when accessing it from IE, the website goes nuts. It keeps refreshing every few seconds and it was unusable. I tried Chrome but apparently there is an issue with this browser. When I enter my login details, it keeps prompting me to enter my username and password without success.

I tried removing the cookies but still nothing worked. Then I remembered that about a week ago, I changed my work’s account password, so maybe that was the issue. I tried to log out from SharePoint, which I managed to do successfully, but when logging in again, it started refreshing the page again.

Reset

Finally I tried resetting Internet Explorer, and that did the trick (p.s. to reset IE, go to Internet Options, click the Advanced tab, and click the Reset button). I asked around, and some colleagues had the same issue after resetting their password. I’m still not sure why it’s happening, so if anyone has any other solution instead of resetting Internet Explorer, please add it in the comments below. Thanks!

Facebook Tips for Businesses

Do you want to know how to choose your business page name? Do you know how to check if page names and usernames are available on several social media websites? Do you want to create your business page? And upload high quality cover photos and profile photos? Then follow this link on Deep Design’s blog to find ‘Facebook Tips for Maltese Businesses’ post (most of it also applies to global businesses as well).

Blog Post: Facebook Tips for Maltese Businesses #Setup
Website: Deep Design

Improve Website Performance with Lowercase URLs #SEO

At work we are always seeking how to make our websites use fewer resources and perform better. One of the performance increase was found by having Lowercase URLs. From the testing done, it resulted that Lowercase URLs make an average performance improvement of 10%. A big improvement with minimal effort.

How do you make sure that all the URLs are in lowercase? In MVC ASP.Net, you just need to add 1 line of code.

Continue reading