Archive For The “.NET” Category

Deferring starts with Castle’s StartableFacility

If you’re using Castle Windsor as your IoC container, the StartableFacility is great simple way to start up services like timers, socket listeners, etc that run for the duration of your application and require two-step initialization — i.e., constructing them then starting them. All you have to do is implement an IStartable interface, with a [...]

Read more »

Recording the git commit hash in your assembly with TeamCity

If you’re using SVN, you can very easily configure TeamCity to insert the commit revision number into the assembly by using the built-in AssemblyInfo Patcher with a pattern like 1.0.0.%build.vcs.number%. This works because SVN and .NET both use integers for their version numbers. Git, on the other hand, uses a 40-character SHA-1 string as a [...]

Read more »

Quick-and-dirty unique constraints in Raven DB

Raven DB, like most NoSQL databases designed to be fast and scale out, does not readily support enforcing uniqueness of fields between documents. If two users must not share the same email address or Facebook ID, you cannot simply add a unique constraint for it. However, Raven DB does guarantee uniqueness in one place: each [...]

Read more »

Fast empty Raven DB sandbox databases for unit tests

Say you you have some NUnit/xUnit/Mspec tests that require a live Raven DB instance. Specifically: You do not want your test to be affected by any existing documents, so ideally the Raven DB database would be completely empty. Your test may span multiple document sessions, so doing it all within a single transaction and rolling [...]

Read more »

Object-oriented basics: single object or collection scope?

Here is a contrived example of a common SOLID violation you might see. Can you spot it? Except in trivially simple cases, there should always be a class boundary when shifting context from coordinating a collection versus performing actions on a single object. The class above is violating this rule — it knows how to [...]

Read more »