soygul/NBug — pull request #4 by vegardlarsen (2013-05-01 13:03:29+00:00)
Title: Interface-based protocols.

Moves to an interface-based protocol implementation as suggested in issue #2.

This introduces two new interfaces:

```cs
public interface IProtocol
{
bool Send(string fileName, Stream file, Report report, SerializableException exception);

string ConnectionString { get; }
}

public interface IProtocolFactory
{
IProtocol FromConnectionString(string connectionString);

string SupportedType { get; }
}
```

To implement a protocol with support for connection strings, you need to implement both.

The `Send()` method is pretty self-explanatory, but this ensures that the protocol gets all the information it needs regarding the exception. The read-only `ConnectionString` property is meant to allow the protocol to create its own connection string for serialization.

`IProtocolFactory` is necessary because we cannot otherwise guarantee that a protocol is instantiable using reflection (e.g. it would need a constructor with a single parameter that takes a connection string). Instead, the factory instantiates the correct object.

The `SupportedType` is the Type identifier from the connection string. This allows us to read connection strings and pass it to the correct factory by looking at the type.

Implementations of `IProtocolFactory` are found using reflection over all loaded assemblies. This is done using lazy loading, so the potentially slow reflection will not happen until it is explicitly needed.

These changes have made the `DestinationX` properties on the `Settings` class redundant, and they have been replaced with an `ICollection Destinations` and a helper method `AddDestinationFromConnectionString()`. Most other changes in the pull request follow from this removal.