I'm creating an assembly that a yet-to-be-developed application will be using to communicate with a device via System.IO.Ports.SerialPort
I want to use StructureMap to pass an interface to a class which will act as a wrapper around SerialPort into the constructor of the class representing the device I'll be communicating with.
e.g.
public interface ISerialPort
{
Handshake Handshake { get; set; }
bool IsOpen { get; }
event SerialDataReceivedEventHandler DataReceived;
void Close();
void Open();
string ReadLine();
string ReadExisting();
}
public class MyDevice
{
private readonly ISerialPort _serialPort;
public MyDevice(ISerialPort serialPort)
{
_serialPort = serialPort;
}
}
I also intend to use this approach to facilitate unit testing.
I've used StructureMap before with web/desktop applications that have had either Application_Start
or a Main
method, which I could use as an entry point to configure StructureMap. However, as this is a stand-alone assembly without a single entry point I can't do the same.
As such, what is the best way for me to configure StructureMap for use in an assembly?