Przejdź do głównej zawartości

Posty

MongoDB for C# developers - Lesson 1

Today I'll show you what I lerned at Mongo University online course for C# developers after first lesson and passing all homework.
I'll show you how you can:
- install MongoDB on Windows workstation
- switch between databases
- display all elements from a collection
- add new document to a collection
- restore Mongo database from a dump folder.


Get MongoDB installer from MongoDB download center:
https://www.mongodb.com/download-center

After installation of 64 bit version go to C:\Program Files\MongoDB\Server\3.4\bin.
You should see there 2 files:
-mongo - this is a console application, you can think of it as a client application
-mongod - this is a server of database

At this point it's useful to add 'C:\Program Files\MongoDB\Server\3.4\bin' to PATH environment variable.


Now open the command line and go to C drive.
Create the folder by using command:
mkdir data\db
And now run the server:
mondog
Important: If you forget adding the data\db folder then server will stop ju…
Najnowsze posty

Up and running with Laravel

Today I'll show you how to start working with Laravel - a modern PHP framework.

After reading this article you'll be able to:
- Install XAMPP
- Configure Virtual Hosts on Apache
- Create your first application in Laravel
- Run the application
- Start coding

As a first step I encourage you to visit Laravel.com to get some background knowledge about Laravel.


Laravel is a PHP framework which is build on top of the MVC pattern (MVC stands for Model View Controller).
You can find general explanation of MVC design pattern with some code examples written in Java here.

I assume that you've already installed XAMPP which has version for Linux, Windows and OS X.
Personally I'm using Windows in this tutorial but on each operating system it should work similarly.
You can get the installer of XAMPP from this page: https://www.apachefriends.org/pl/index.html.
When installer prompts you which options you want to install, you need to select Apache and you are free to skip the rest opti…

Learning e24cloud.com API

Today I'll show you how to use API in order to create virtual server in the cloud directly from your code.
We're going write a script in PHP language and use Amazon SDK API to connect with e24cloud.com, which is the biggest and most modern hosting provider in Poland.

First we need to install Amazon SDK http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html

One important note:
We can use the latest version of amazon SDK but we also need to do one trick.
We'll use signatureV2 instead ov Signaturev4 as e24cloud doesn't support SitnatureV4 yet. You can download it here: https://github.com/aws/aws-sdk-php-v3-bridge

We need to download SDK and the bridge which allows us to use Signaturev2 to the same folder, so that require instruction work seamlessly in the form that I provided in the example below.

Then go to your admin panel in e24cloud.com to find two values: a key and a secret. In the following code you need to paste those 2 values. I used 2…

Xamarin.Forms Previewer

Today I'll show you a tool for every Xamarin developer - Xamarin.Forms Previewer - a tool which will help you to design Xamarin.Forms views faster.

First we need a xaml view:

The view can't be easier. It contains only one label.
Now let's build the project and open Previewer from the View Menu:


It should results in displaying the new window which renders your xaml view:


Now the most interesting part. Let's add a few labels and change the screen background color. There is no need to save, the design will be changed on the previewer instantly.

This is a Xamarin.Forms previewer. I'm using it because it speeds up my view desting loop. I don't need to run the app on emulator or a device to see effects of my changes.

Dependency Injection in .NET Core

Today I explain how Dependency Injection works in .NET Core and I describe 3 methods available in service provider.
Up to now if ASP.NET developers wanted to use dependency injection container they had to use Ninject, Autofac or another one.
To set these up we had to get NuGet package, install it and configure it in our config filels.

Good news - with ASP.NET Core new alternative comes. We don't need Ninject or Autofac anymore, because ASP.NET Core MVC has its own built-in dependency injection container.
All set up when new project is created. There is no need to install packages and modifying configuration files.

There are 3 methots that we can use to define dependencies in ASP.NET MVC: transient, singleton, scoper
Let's open Visual Studio and create new ASP.NET Core MVC application.

We'l focus on Startup.cs class where you can see ConfigureServices method.
If you want to instruct MVC to use specific class when controller asks for IEventRepository interface, you should p…

Xamarin Live Player

In this article I'll show how to install and use Xamarin Live Player.


The tool called Xamarin Live Player is a new mobile application and let's you show and modify your Xamarin application on the fly and see effects in your phone or tablet immediately.

First you have to install the newest Visual Studio 2017 preview 15.3.
Next we need to download Xamarin Updater: https://marketplace.visualstudio.com/items?itemName=Xamarin.XamarinUpdater
Then follow the instruction: here .

When Visual studio is set up we need to install new software on our mobile device.
You can find Xamarin Live Player in Google Play store:


Next let's go to the Visual Studio 2017 and create a new Xamarin.Forms project:

Now we should see a new device called "Life Player" in our list. Let's click the green arrow button:

You'll be presented with pop-up windows with QR Code.

Now take your mobile phone where you've installed Xamarin Live Player and scan the code that Visual Studio has disp…

How MongoDB + good programming practices saved my time

Today I'll show you how in I'm using MongoBD in web service part of Perfect Life application. I'll show how using good programming practices saves time.
I switch database to brand new instance of mongoDB. And I did it. And all that you'll see today was made within one hour. Interested? Keep reading...

As you know I tend to use interface to connect components in my application. It helps me to keep components loosely coupled.
For example I use dependency injection where controller uses IWeightRecord Repository.


Using interfaces this way makes it easy to switch my repository to something else.
In my case I'd like to create a new repository that depends on Mongo database instead of in-memory repository that uses Dictionary.
As the reault my data won't be deleted in case of web application restart. This is my target.
So first I'm adding a new Nuget package to my WebAPI application. The package is called MongoDB.Driver.
Next step is to create a new repository tha…