Blog Home  Home Feed your aggregator (RSS 2.0)  
Eric Malamisura's Blog - Friday, February 15, 2008
Geek Ramblings
 
 Friday, February 15, 2008

Windows Vista SP1 is on Vista right now, albeit through a special link since it doesn't show up through the normal login page just yet.  So go here http://msdn2.microsoft.com/en-us/subscriptions/default.aspx

Click it, login using your MSDN Subscription and money money money!

Friday, February 15, 2008 12:36:36 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]    | 
 Thursday, February 14, 2008

So apparently Vista SP1 Final will be available to all MSDN Subscribers by the end of this week based on a blog post on the MSDN blog.  Also you can view ALL of the changes that ended up going into Vista SP1 here.  I installed the Beta and was very impressed with the speed improvements, and even though most people claim stability problems I really didn't have any stability issues left with Vista before installing SP1.  Most of my stability issues have vanished with the latest driver updates for my hardware.  However, with SP1 there were some substantial performance increases that I noticed immediately after installing.

Thursday, February 14, 2008 1:39:42 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]    | 
 Monday, February 04, 2008

So ever since I have started working with Visual Studio 2008 I find myself hitting shortcut keys that just don't exist anymore.  I have been denied my ReSharper abilities and it is really humiliating to work without them, I miss my ReSharper.  But soon, very soon in fact by February 15th the good folks at JetBrains will be opening up the Early Access Program for ReSharper 4 and not soon enough! 

Thank god! That is all I have to say, working with ReSharper substantially improves my code quality and code output. You can read all about this on ReSharper Horizons blog.

Monday, February 04, 2008 4:38:30 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]    | 
 Sunday, February 03, 2008

So I have been exploring DI Frameworks lately (Dependency Injection), and there are a couple of solutions.  While I kind of like the metadata approach vs. the XML Configuration one there really isn't anything available yet.  You have ObjectBuilder, but its only a DI Framework, it doesn't include a DI Container so you are left to build your own container, which includes setting up all of your strategies, context, etc.  The CodePlex guys are apparently working on an ObjectBuilder v2 which they are trying to get vetted by the P&P team at Microsoft.

So the choices are:
Spring.NET
StructureMap
Castle Windsor Container

I have been evaluating these mostly because of a hobby project I am working on called VistaTune, I would like to use a DI Framework and the current changeset that is checked in is using Spring.NET but I am not happy with Spring.NET for a couple of reasons.  First there is no real way to control your dependency injection dynamically, its all configuration based.  Secondly there is no way to inject an instance into your container, for example during unit testing I would like to inject a mock to override the real instance that is mapped in the configuration.  Thirdly there is no DSL (Domain Specific Language), and appears to be no DSL planned for the future release.

Note: After posting this Jeremy D. Miller the developer of StructureMap updated me, the current version of StructureMap v2.0 already has DSL but the next version is being extended with even more.  See the comments section below, also visit his blog here for more information.

For those reasons, I am leaning towards using StuctureMap, which in current release has no DSL but next release will which is already in testing so its pretty much done.  It supports container injection, and it allows you to reset your injection so you can revert back to the original container before injection which is really cool.  It also supports interception, among other things that are out of the scope of my assessment.

So which DI Framework?  It is a difficult question to answer, and I really think it will be interesting to see what comes about from the current top runners at the moment.  I expect to see big things from Microsoft on ObjectBuilder, especially since they just released their PIAB (Policy Injection Application Block) which is their solution to an AOP (Aspect Oriented Programming) Framework.  I would personally rather see PIAB stay isolated by itself, I prefer small isolated Frameworks rather than huge bloated ones that you only want to use for a single thing. 

Sunday, February 03, 2008 8:14:29 AM (GMT Standard Time, UTC+00:00)  #    Comments [1]    |   | 
 Sunday, January 20, 2008

Ok, so the previous post I discussed a service locator implementation based on the Martin Fowler registry example.  After some thought and discussion with a couple of friends I decided the previous implementation was a bit too strict for it's own good.  So I have come with a way that still gives you generic goodness, it does however suffer from boxing/unboxing which may give you a slight performance penalty vs. my previous implementation but the penalty should be minimal if noticeable at all.

The new service locator implementation:

  public interface IService { }
    public class ServiceLocator
    {
        private static ServiceLocator _instance;
        private ServiceLocator() { }

        private static Dictionary<string, object> _map = new Dictionary<string, object>();

        public static ServiceLocator Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new ServiceLocator();
                }
                return _instance;
            }
        }

        public void Load<T>(T service) where T: IService
        {
            Load(typeof(T).FullName, service);
        }

        public void Load<T>(string key, T service) where T : IService
        {
            _map.Add(key, service);
        }

        public T Get<T>() where T : IService
        {
            return Get<T>(typeof(T).FullName);
        }

        public T Get<T>(string key) where T : IService
        {
            return (T)_map[key];
        }
    }

To use this the syntax is slightly different than before, this time everything is method based.  I still constrain the methods to the IService type, for some reason  it just gives me a warm and fuzzy feeling when I use the constraint. It is obviously up to you whether or not you want to use it, you could delete the marker interface and the constraints completely and it will work just fine.

To Get: MyService wmiService = ServiceLocator.Instance.Get<MyService>();
To Load: ServiceLocator.Instance.Load<WMIService>(new WMIService());

So both versions work, both versions are acceptable solutions but this one is more flexible than the last version.  In particular this version allows a greater degree of flexibility around unit testing and mocking frameworks.

Sunday, January 20, 2008 7:12:03 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]    | 
 Wednesday, January 16, 2008

So I came across the need for a service locator but I didn't want to use a framework since my needs were relatively lightweight, and mostly based around testing.  So looking at Martin Fowlers examples of Service Locators I adopted them and came up with a .NET way of doing it using Generics.  It is of course flexible, the method I am offering obviously has a couple of constraints that I have put in place on purpose for my scenario.  One of them being I wanted only one instance of a service set in the service locator at any given time, so you could very easily adapt it to suit your own needs. 

Also the interface specified is a marker interface used to specify a constraint on the generic, the idea was that all services would be marked with this interface.

 public interface IService { }

    public class ServiceLocator<T> where T : IService
    {
        private static Dictionary<string, T> _map = new Dictionary<string, T>();
        private ServiceLocator() { }

        public static void Load(T service)
        {
           _map.Add(typeof(T).FullName, service);
        }

        public static T Get()
        {
            return _map[typeof(T).FullName];
        }
    }

An example of a service would be like follows:

public class MyService : IService
{
    //Whatever Methods
}
Then on application startup you would obviously load all of your services into the service locator:
MyService myService = new MyService(...);
//...do whatever you need to setup the service

ServiceLocator<MyService>.Load(myService);

So later on anywhere in your code you simply do a

MyService myService = ServiceLocator<MyService>.Get();

It's pretty simple but just in case...As you can see I chose to use the FullName of the type as the key in map, you could always choose to do it the way Martin Fowler did where you simply expose the instance of each service type directly but for me I kind of liked this method.

 

Wednesday, January 16, 2008 5:15:04 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]    | 
 Sunday, December 30, 2007

Been working on a new application called VistaTune, it is open on CodePlex so you should go check it out but basically its an application that will enable you to tune Vista as well as setup profiles to use for certain "modes" such as gaming, developing, etc.  In any case during my development I noticed that the ServiceController class of .NET is lacking in that it does not allow you to change the Startup Mode of a service.  Personally I find this kind of odd since it lets you do everything else, so I went ahead and wrote an Extension Method for this class.

The below code is the cleanest and quickest implementation I could come up with, note that editing the registry to change the behavior of a service is considered evil and is very problematic so I would not recommend that route.

        public static void ChangeStartMode(this ServiceController sc, ServiceStartMode mode)
        {
            ManagementPath managementPath = new ManagementPath()
            {
                Server = System.Environment.MachineName,
                NamespacePath = ManagementPath.DefaultPath.NamespacePath,
                RelativePath = String.Format("Win32_Service.Name='{0}'", sc.ServiceName)
            };

            //Method: ChangeStartMode, Parameters: Mode (string), Return Value: int (0 success)
            new ManagementObject(managementPath).InvokeMethod("ChangeStartMode", new object[] { mode.ToString() });
        }

I hope this helps anyone that is having this problem, I did not find very good solutions to this problem when I was searching for it.  Also most of the code samples I found were very dirty, created lots of objects that were not necessary, etc.

Sunday, December 30, 2007 5:15:05 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]    | 
 Monday, July 16, 2007

If you bind a property to a UI element and then changed the value of that property on the back end entity the UI will not reflect that change unless you update the UI manually right?  Well no, not entirely true, and in my case I am going to speak WPF because I do not know if this is available in WinForms since I never used it in WinForms.

Let's say for example you have a ListView control that is bound to "Balance" for all 45 items, let say you have a background thread that is processing and is going through the records and updating this value.  How nice would it be for the UI to automatically update when this happen?  Well it's easily doable since binding automatically supports this functionality.

All you have to do is implement the INotifyPropertyChanged interface on your entity, after which you will get a new event.  Then in the method or property setter you fire this event, the UI will be watching for it and it will automatically fetch the new value for the value you specified.  This should also be faster since you don't need to update the entire binding context of the control.

Simply call PropertyChanged(this, new PropertyChangedEventArgs("Balance")) and only the specified property will update.

Monday, July 16, 2007 5:25:21 AM (GMT Standard Time, UTC+00:00)  #    Comments [1]    | 
Copyright © 2009 Eric Malamisura. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.