Finding them windows

If you’re working with a laptop and you’re used to have a second monitor attached, you might tend to place some apps/windows on the secondary screen.

Once in a while you might start your laptop without having this handy little second monitor (for e.g. on the road :)) while traveling). Some apps tend to popup on the screen they were last used – and this is according to Murphy’s Law always the second monitor which is right now neither available nor connected.

So in order to access the app, you can do the following little trick:

  1. start the app (which is being displayed on the “wrong” display)
  2. click on the context-menu of the app in the taskbar and select “move”
  3. even though you don’t see the mouse-pointer/cursor move the mouse towards your primary display (if the second monitor is to the right of your laptop, the you might want to move left 🙂 ).
  4. you should see your app moving into sight!

Waiting for the SQL

Sometimes you just need a slow query to simulated a real big load of data being processed by the SQL-Server. You could either fill-up you database with a whole shit-load of data, or you use WaitFor Delay instead:

WaitFor Delay '00:00:10'

Will pause the execution of the SQL-statement for 10 seconds – well, isn’t that sweet.

Remember the cicle of life!

I thought – hey, let’s use the WindsorContainer deal with all my dependencies, that exist in my presenter-class. So I don’t have to worry about all the kinds of repositories and other stuff I might need. So I added my presenter:

_nestedContainer.AddComponent(
"SelectionPresenter",
typeof (SelectionPresenter));

But when I accessed my presenter from a ASP.Net webpart, registered some eventhandler on the presenter, which pointed back to the WebPart:

public class MyWebPart : WebPart
{
protected override void CreateChildControls()
{
var presenter = Container.Instance.Resolve<SelectionPresenter>();
presenter.OnItemSelected += HandleOnItemSelected;
}
[...]
}

Then I raised the event (in a postback!!) which sould be handled within the WebPart – boom! NullReferenceException while accessing the WebPart from the presenter!

After an enourmous amount of time I finally figured it out … the default behavior of the WindsorContainer is to provide singleton instances of objects. So in my case the presenter is being created the first time the WebPart is executed, and when the postback occurs the same instance of the presenter is being returned – this is wrong!

OK, so changing the component-registration did take care of this problem:

_nestedContainer.AddComponentWithLifestyle(
"SelectionPresenter",
typeof (SelectionPresenter),
LifestyleType.Transient);

Having a one-to-one with nhibernate objects

So after getting my latest project up and running I wanted to look behind the scenes, and to do so I took a deep look into the sql-statement which are being executed against the database – yes I know, this might seem a little geeky.

So I figured, that I have two objects A and B which have a one-to-one association. And since I declared B to be lazy loaded from A I expected only to hit the ‘A’-table when fetching all ‘A’s from the DB. But I was far off – A and B where both completely scanned 🙁

After some quick google-ing I figured – this is just the way a one-to-one association works; there is no lazy loading! 🙁

OK, so I might switch to use something else instead …