Tuesday, February 22, 2011

Kinect Third Party Apps Development will be officially supported by Microsoft

This are great news. Microsoft has announced that it will release an official SDK for Kinect third party development, officially confirming that the use of the Kinect as a third party application development device is being formally encouraged by the software giant !

More info here.

Cheers!

Saturday, February 19, 2011

Factory Pattern Using Unity Application Block

I have been working with the Unity Application Block lately and I keep getting learning new things. I wanted to share with you how you could implement the Factory Pattern when you are working with Unity and how it can make your life easier.

With Unity you can have the interfaces and their concrete implementation mappings in the Unity configuration file, giving you great flexibility to map whatever interface you want to their implementation. This way unity container will be able to resolve any contract you pass along.

     /// encapsulates the instantiation of data provider classes
    public static class Factory
    {
        private static readonly string containerName = "DALContainer";
        private static readonly IUnityContainer container;

        static Factory()
        {
            if (String.IsNullOrEmpty(containerName))
            {
                throw new InvalidOperationException();
            }
            container = new UnityContainer().LoadConfiguration(containerName);
        }

        /// Instantiates a data provider class
        public static T CreateProvider < t >()
        {
            return container.Resolve < t >();
        }
    }

Then the only thing you need to do when you need to instantiate your data provider class ask your factory for it:

IUserProvider dataProvider = Factory.CreateProvider < IUserProvider >()

Notice how less code you need to implement the pattern and encapsulate the functionality with the convenience of leveraging the class resolution into a configuration file, which you can change without having to recompile the application !

Hope the tricks help out there.

Cheers!
-arbbot

Friday, February 18, 2011

What is SOLID

I was reading a few posts about OOP and I wanted to write about what is SOLID and why is so important. Lets start by the formal definition:

SOLID stands for:

S - Single responsibility principle (SRP):
The notion that an object should have only a single responsibility. You know how hard it can be to find the source of a bug/issue. If you encapsulate and abstract the functionality of your object, reducing its responsibilities to a single one, it would be a lot easier to find out if the problem is being generated by that object. The reason it is important to keep a class focused on a single concern is that it makes the class more robust. Look out for the separation of concerns concept, that´s a big deal in software development and software architecture.

O - Open/closed principle (OCP)
The notion that “software entities … should be open for extension, but closed for modification”. OOP basic principles. Inheritance, polymorphism and abstraction. Any good developer should understand and apply this principle.

L - Liskov substitution principle (LSP)
the notion that “objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”. See also design by contract. Put your interfaces to work dude, make sure you work with contracts, so you can modify, extend or replace implementations without breaking the whole thing !

I - Interface segregation principle (ISP)
The notion that “many client specific interfaces are better than one general purpose interface.” Again, we are trying to encapsulate and abstract functionality. The days of "one big file" are far behind, you should divide and conquer always, and not try to just throw everything in a single place.

D - Dependency inversion principle (DIP)
The notion that one should “Depend upon Abstractions. Do not depend upon concretions.”
Dependency injection is one method of following this principle. Dependency inversion is a very useful concept to understand, although I think is not that easy to master. This has become more important with frameworks and standard libraries and is about reversing the control in a program´s life cycle. Dependency Injections is related to the concept and is one of the methods to achieve it. Check out Enterprise Library and the Unity Application Block for .NET specifics and keep reading and revising general software development articles and documentation about DI. Its worth it.

Cheers!
-arbbot

The Three Laws of the "Indi" Developer

1 - A developer may not injure its Client or, through inaction, allow the client to come to harm.
2 - A developer must obey any orders given to it by the Client, except where such orders would conflict with the First Law.
3 - A developer must protect its own existence as long as such protection does not conflict with the First or Second Law.

Wednesday, February 16, 2011

Unity Application Block Configuration File Setup

Recently I have been working on a C# backend project were we are using the Unity Application Block (Unity) injection features to enable our backend to inject dependency mappings between the Data Abstraction Layer (DAL) and the Business Abstraction Layer (BAL).

"The Unity Application Block (Unity) is a lightweight, extensible dependency injection container with optional support for instance and type interception."

This architecture approach and the use of Unity allow us to completely decouple the BAL from the DAL layer increasing the extensibility and maintainability of the system. We also get the advantage of simplifying object creation when applying the Factory Pattern for dynamic class instantiation/resolution. It also give us greater abstraction and allow different team members to work on different layers reducing the dependencies and increase the flexibility by deferring component configuration to the container.

Configuring Unity is generally straight forward, but your configuration file can become quite big, complex and difficult to manage. What we do to solve this issue, is to separate the unity configuration into a different file, say "unity.config". I wanted to share the tip on how to implement this approach of having multiple configuration files, breaking down the configuration settings and simplifying each of the config files.

First, you need to include the Unity config section in your main configuration file:


And then specify which is the file containing that configuration file:


And voila. Once you have the unity.config file in place everything will work and you will be able to retrieve the Unity configuration settings from the secondary unity.config file.

Now remember that on the unity.config file you need to specify the Unity container. The unity.config file should look something like this:


But since in your application code you will be resolving the container dynamically, you need to be able to retrieve the container configuration. For this, you will need to include the container name in the main configuration file as an application setting:


Then in your code, you can simply retrieve the container name from the configured app settings:

private static readonly string DalContainerName = ConfigurationManager.AppSettings["DALContainer"];

Then to resolve your container when creating the classes on the factory class, you need to declare a unity container and then resolve the container:

private static readonly IUnityContainer Container;
Container = new UnityContainer().LoadConfiguration(DalContainerName);

At this point you have loaded the container specific configuration and dependency mappings, so you can go ahead and resolve the class you need:

        public static T CreateProvider() where T
        {
            return Container.Resolve();
        }

Where "T" will be the interface type (declared in the BAL layer) you need the container to resolve. That will give you the concrete class instance that implements the given interface. Remember that the interface will be declared at the BAL layer while the concrete class implementing the interface will be implemented in the DAL layer.

I hope it helps you out there to get the most of your configuration files, and I recommend keeping an eye on the Unity Application Block for extensible, loosely coupled application development.

Cheers!
-arbbot

Thursday, February 10, 2011

Getting DB project into Visual Studio

Related to my previous post, I had some issues importing the existing DB schema into the Visual Studio 2010 SQL Server 2008 Database project because an unresolved reference between the DB user (database level) and the DB login (server level). I found this issue on a forum and the answer to the problem here which basically indicates that you need to add both a database project and a server project. When you have added both projects and synchronized them with the existing database, you can add a reference to the server project in the database project and voila, issue solved. Hope it helps !

Cheers!
-arbbot

Cannot load file or assembly "Microsoft.SqlServer.Management.SqlParser"

Error: Cannot load file or assembly "Microsoft.SqlServer.Management.SqlParser"
Scenario: Adding a new SQL Server 2008 Database Project in Visual Studio 2010

I wanted to share the issue I found today while trying to create a SQL Server 2008 Database project in Visual Studio 2010. I have an existing database project in SQL Server 2008 and I wanted to include the database project in Visual Studio 2010 for Source Control Reasons. If you want to create a SQL Server 2008 DB Project you need to follow these steps:

1 - Right click on the Solution or Solution Folder where you want your db project to be created.
2 - From the project templates dialog box, go to the Database Node and select the template you want.


You can also find a step by step tutorial on how to create a new DB projects in Visual Studio 2010 here or how to include a existing DB in Visual Studio here.

Now the issue was that when I selected the SQL Server 2008 Database project, Visual Studio game me an error saying that "Could not load file or assembly Microsoft.SqlServer.Management.SqlParser, Version=10.0.0.0...blah blah blah"


This seemed quite estrange since I had SQL Server 2008 with SQL Management Studio and Visual Studio 2010 working just find for all the other tasks I was working on. Doing a little online research the first thing I realized was that getting the right answer for this error was very difficult. Most forums and articles I found suggested that I needed to reinstall Microsoft SQL Server 2008 Management Objects (SMO) components, or reinstall Visual Studio, which I wanted to avoid. I tried to download and install SMO components individually but it didn't work. At last my colleague Herberth Madrigal shared this link on how to install individual Visual Studio components.

Basically I had to first mount my image of the Visual Studio installer and then find the individual installers directories. Most of them are under the "WCU" folder. Then I had to install the following individual components:

SQL Server System CLR Types
SQL Server 2008 R2 Management Objects
Microsoft SQL Server 2008 R2 Data-Tier Application Framework
Microsoft SQL Server 2008 R2 Data-Tier Application Project
Microsoft SQL Server 2008 R2 Transact-SQL Language Service

Note that to install the individual components, you need to open the command prompt window, navigate to the directory where the component installers are located and then enter the install command "MSIExec /i" followed by the specific command to install the component, which you can find in the link mentioned above.

Remember to do all this after you closed Visual Studio and also remember to restart your computer after the install process of all components has finished.

After restart, run Visual Studio and you should be able to add your SQL Server 2008 Database project to your solution.

Thanks to Herberth for the link and the install process help !

Cheers!
-aB




Google Mail Label Filter

Today my mentor and colleague Murven taught me how to use label filters in Gmail, which is something I always wanted to do, but didn't know how. It turns out that is really easy to do.

To filter your inbox using filters, you just need to enter the text "label:" followed by the label you want to filter your inbox by in the search box above your inbox.


Let's say you have emails tagged as "Family" so you can enter the following: "label:Family" and Gmail will filter the emails displayed by the tag "Family". You can also combine tags for filtering, which is very helpful: "label:Family label:unread". You will also notice that Gmail doesn't real time tag checking, so if you enter a tag that you haven't created Gmail will tell you. Also, the label filters are deep linked, so you can actually work out with URLs. In the case I mentioned above, the last part of the URL in the address bar will look similar to this: "?AuthEventSource=SSO#search/label%3Aunread+label%3Ainbox". Nice huh?

Anyways, simple and easy tip but really helpful. I hope it helps you to keep your inbox more organized.

Cheers!

Wednesday, February 9, 2011

2011 Roadmap

As usual, I have been busy with all my professional and artistic activities. Right now I'm finishing my funky alternative band's first album with the independent producer Automata. We are in the final steps before sending the album to England for the masterization work. You can find more details in the band's page.

I have been also reading a lot of new and old books and I have been hearing that little voice in the back of my head telling me to start writing again. I used to write a lot of poetry and short tales when I was in high school studying literature and poetry. My high school is an arts conservatory mixed with all the other traditional academic classes and I dedicated myselft to study painting, poetry and acting.  I stopped writing when I started to study Computer Sciences and act professionally in theaters and television, it was just a switch of my arts field focus. Lately I have been trapped by "The Name of the Wind", first fantasy novel of Patrick Routhfuss and I must say it is a wonderful and totally immersive book that inspires me to go back to writing. We will see how it goes !

Although I haven't been doing much Acting work in recent years, I have been doing a lot of radio commercials and voice over for different agencies, which is always fun.

On the technical field, I left Mysterious Development in December since I got an offer to work on a really big, cool and complex .NET backend project. I really enjoyed working on game development, specially having the opportunity to learn how to develop games with Unity3D and C#/Mono but I love .NET technologies and the current project and team is awesome and with an international quality level, so I'm very happy with the move and the current work. I have been working with WCF, Windows Services, RESTful services, ASP.NET, MS SQL, SQLite, WebORB and LINQ.

I'm planning some big changes soon, so hopefully this year will be full with opportunities, challenges and learning. I'll try to make some time and post some of the things I have been working with and learning during these months.

Cheers!
-arbbot

Monday, February 7, 2011

Good Reads Update: The Name of the Wind by Patrick Rothfuss

The Name of the Wind (Kingkiller Chronicle, #1)The Name of the Wind by Patrick Rothfuss

My rating: 5 of 5 stars


Reading the book right now. Magical and organic, impress by the way the book is written and how the story is told. I read Kafka when I was 12 years old, and The Lord of The Rings when I was 13 years old. I'm 30 years old now, and Rothfuss's book has such power that takes me away from reality and sometimes is very hard to come back. It gives me the same strong feelings of the great books I read more than 15 years ago. Wonderful book from a master writer.



View all my reviews