Browsing:

Category: Buttonfactory

The Daily Tooltip from the Button Factory

Want tooltips every week? Then like our facebook page and receive a daily tooltip from the Buttonfactory!

tooltip

 


Happy birthday to us! 5th anniversary

itslet5jrHappy birthday to us…happy birthday tooo us!!! This month we celebrate the fifth anniversary of the Buttonfactory.

So we made a very special 5th anniversary facebook page so you can send us your birthday wishes:)

Or you can ask us a question about a topic you would like to see us cover and in January we will  pick the best questions!

https://www.facebook.com/thebtnfactory

 


First steps with RavenDB and ASP.NET MVC with Ninject

I have been meaning to try RavenDB for more than a year now. I’m sure this blogpost duplicates lots of other intros of Raven but I’m writing this for me and I hope that it has some positive side effects for other beginners as well.

Why Raven? In my particular case, I want to have a quick way of storing and retrieving objects because I want to focus on business logic and also the client side (coffeescript, AJAX, json and the likes).

So first, install RavenDB through Nuget.This gets you also the RavenDB server so click on the executable, check localhost:8080 and go.

This is the class diagram:

Let’s get started.

This is how to connect with the RavenDB documentstore:

[code lang=”csharp”]
[TestFixtureSetUp]
public static IDocumentStore StartStore() {

var documentStore = new DocumentStore { Url = "http://localhost:8080",

DefaultDatabase = "TestDatabase"

};
documentStore.Initialize();

return documentStore;
}
[/code]

Look how easy it is to define a testdatabase. Imagine how you can run different instances next to each other.

Now let’s insert some data:

[code lang=”csharp”]
[Test]
public void Insert()
{
var documentStore = StartStore();
using (var session = documentStore.OpenSession())
{
var person = new Person {Achternaam = "Summer", Roepnaam = "Donna"};
var note = new Note {Person = person, Notitie = "Called"};
session.Store(person);
session.Store(note);
session.SaveChanges();
}

//I don’t want an Exception
Assert.Pass();
}
[/code]

And retrieve them:

[code lang=”csharp”]
[Test]
public void Retrieve()
{
var documentStore = StartStore();
using (var session = documentStore.OpenSession())
{
var person = session.Load("people/129");
var notes = session.Query().Where(y => y.Person.Id == person.Id);
//hope this fails
Assert.Null(notes);
}
[/code]

Well, this is all so simple. It’s almost not worth a blogpost. Woohoo!

Now let’s hook it up in ASP.NET MVC 3 using Ninject.

I found this to be an excellent resource, written by Dalsoft (look here).

In short: add the nuget package for Ninject:
[code lang=”csharp”]
Install-Package Ninject.MVC3
[/code]

This creates a new App_Start folder in your Web project.

Then, add a class named RavenDBNinjectModule and make it look like so:

In NinjectWebCommon you only need to add:

[code lang=”csharp”]
private static void RegisterServices(IKernel kernel)
{
kernel.Load(new RavenDBNinjectModule());
}
[/code]

And that’s it. You’re set.

This is how to inject Raven in the Controller:

[code lang=”csharp”]

public class HomeController : Controller
{
private readonly IDocumentSession _documentSession;
public HomeController(IDocumentSession documentSession)
{
_documentSession = documentSession;
}
[/code]

I’m so impressed by the simplicity of all this.

Of course, this was just a tip of the iceberg. No, it’s the tip of the tip of iceberg. It’s the tip of the tip of the t..
You get my drift.

Follow along: here.


PHP MVC for an ASP.NET MVC developer part 1. Setting the stage.

Jacqie has a little LAMP!

What if the customer is hosting their sites on a LAMP server? Let’s write some PHP! This has a few advantages over IIS hosting. It is super affordable and available. However. Can I use the MVC pattern in PHP? Can I do OO in PHP? Can I have a layered architecture?

Searching DuckDuckGo for PHP MVC frameworks returns lots of results and it seems there are many PHP MVC Frameworks. See this list, for example.  Now which one to choose? I want to be up speed as soon as possible. And that said, how to get that the PHP/MySQL stuff onto my Windows laptop?

Which PHP MVC Framework?

The PHP MVC framework I will use, should have a. enough documentation, b. support the latest and the greatest PHP version and c, be awesome. My winners are: CakePHP, Kohana (which is not that well documented and also pretty hard to use re the web but their website looks awesome) and YII.

Install the LAMP on Windows

To get a WAMP running, I picked the Uniform Server because it’s a small download and supports the latest PHP (5.4) and MySQL. It is also highly configurable and supports vHosts and stuff like that.

Download, extract and save it somewhere directly under the root of a drive. (D:)

image

Next, click Start_as_program.exe and start Apache and MySQL:

image

If that doesn’t work, just make sure you stop other webservers you might be running (run services.msc). The Uniform Server defaults to port 80.

When the services are started you see the default server displayed. The website live in the /www folder. Here you can put your php files.

PHP IDE

So, what is the best PHP editor/IDE then? I installed Netbeans, because it is easier than Eclipse, according to this article and I want to get up and running asap.

And what’s so funny. Netbeans supports Git. Look at this:

image

Next time, you make coffee and I’ll be sure we have some CakePHP.


Db4o with Castle Windsor and ASP.NET MVC 3.

This is how you can use Castle Windsor inversion of control container with Db4o. In this example I use the Db4o Server rather than the embedded version.
That’s because I want to be able to make multiple connections to Db4o in an ASP.NET MVC 3 application. So here is how it is. (It is rather short because it is so easy, or perhaps I’m missing things? Let me hear it if I do!).

First, open the package manager console and add the following packages:

[code]
Install-Package db4o-cs-devel
Install-Package Castle.Windsor
[/code]

And in the TestProject:

[code]
Install-Package Nunit
[/code]

To get started with ASP.NET MVC 3 and Castle Windsor, just follow this excellent documentation. Don’t forget however to put this line in your web.config, in the System.Web section:

[code]
<httpModules>
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
</httpModules>
[/code]

I decided to use a generic repository. Since I use a Db4o Server (see the docs), connecting to that Windows Service returns a Db4o session (IObjectContainer). So I can use that session in the Repository.
This is also very testable.
But first let’s hook it up in Windsor:


Isn’t that simple?
We’ll use the IObjectContainer like this in the repository:

And finally, the Controller looks like this:

Please check out the source code here.

The Buttonfactory Db4o Windows Service

I know, this has been done before, here and here, and these people did it much better than I did, but I thought it would be nice to write a Db4o Windows service myself. Just as an exercise. I also wrote a WPF frontend so you can control the service easily:

You can download The ButtonFactory Db4o Windows Service and Configuration Tool here: Db4o.Service.Installer.Setup. Mind you, it is all very beta and I really need to test concurrency.

Here is the complete source code.