1. Hello World

In this tutorial, you will create a hello world service to have a quick feeling on how Gazel works.

If you don't have an empty solution ready, have a look at previous page and come back to this page once you are ready or you can download an empty solution from here.

Create a Hello World Service

To create a new business service, create a class named TaskManager in Gazel.Tutorial.Module.TaskManagement project.

Now add a new method called SayHello to TaskManager class as shown below.

public class TaskManager { public string SayHello() { return "Hello World"; } }

public instance methods of classes within module projects are directly exposed as business services.

Now run Gazel.Tutorial.Test.AppHost.Service project, and you will see a test page to be able to test your services.

On the left you will see that Gazel has rendered your TaskManagement module and listed TaskManager class as a service package, and under Task Manager it lists your SayHello method as a business service. Click Say Hello and press Call button to make a test service request. When you do, you will see a response saying Hello World.

Writing a Unit Test

Now that you have implemented the most basic business service, it is time to test it.

Create a class named TaskTest in Gazel.Tutorial.Test.UnitTest project.

Write below code within this class;

[TestFixture] public class TaskTest : TestBase { [Test] public void SayHello__says_hello() { var taskManager = Context.Get<TaskManager>(); Assert.AreEqual("Hello World", taskManager.SayHello()); } }

Context property comes from TestBase which allows you to access IoC container. Manager classes are singleton by convention, so you can access to TaskManager instance by Context.Get<TaskManager>().

That's it. Now you can run this test to see if it succeeds.

Gazel uses NUnit for unit testing. For more information about NUnit see: NUnit Documentation


As you can see no configuration is needed to create a new service. Once you've created your solution and projects, every public class in module projects becomes a service package and every public method becomes a service by convention.

Now try to add new methods or add parameters, re-run and see the results.

Once you are ready, you can proceed to next page to create your first database operation using Gazel.

You can download complete source code for this tutorial here