Category: Microsoft

  • Passing in “this” in StructureMap

    I’ve been working with StructureMap lately, and struggled when I need to pass this in. The following code is an example of resolving that issue… namespace StateMachine { public class StateRegistry : StructureMap.Configuration.DSL.Registry { public StateRegistry () { For<IState>.Use<StateA>.Named(“FirstState”); For<IState>.Use<StateB>.Named(“SecondState”); } } public interface IStateMachine { void ChangeState(IState state); } public interface IState { void […]

  • MSpec “Hello World” Sample

    I’ve been working with MSpec lately. It’s a BDD framework for .Net. Here’s a hello world type example that uses Trace Writing to show a little bit about what it does. using System; using Machine.Specifications; using System.Diagnostics; namespace UnitedIndustrial.DataImportConcerns { [Subject(“Sample”)] public class SampleConcerns { static string _myString; Establish _context = () => { _myString […]

  • Asp.Net MVC Gotchas

    I’ve been working on a project with the Asp.Net MVC framework lately, and thought I’d write up some lessons learned. I’m using Professional ASP.NET MVC 1.0 as a guide. The first chapter is available online for free as a pdf. One: Be absolutely certain you are avoiding web forms web controls. I took the master […]

  • IEnumerable and Linq

    I was helping someone on StackOverFlow.com and ran into an interesting issue. The post is here. I explained the issue in my response, but I’ll try to sum up. Newer collection types implement IEnumerable(Of T) as opposed to the original IEnumerable interface. For example, System.Generic.List(Of T) implements IEnumerable(Of T), so the following is valid without […]

  • Understanding Read-Only Properties with Object (Refererence Types)

    using System; using System.Text; namespace TestReadOnly { class Program { static void Main(string[] args) { MyClass1 myObject1 = new MyClass1(); // myObject1.MyObject2 = new MyClass2(); // clearly illegal // legal, reference is read-only, not object myObject1.MyObject2.x = 1; Console.WriteLine(“myObject1.MyObject2.x: {0}”, myObject1.MyObject2.x); // also legal, similar to above, anotherObject2 is just a reference to the same […]