0

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?

DaveDev
  • 41,155
  • 72
  • 223
  • 385
  • 4
    Just keep it as proposed. There's no need to involve a DI Container at this point. A container is used by an *application* - not by a library. http://stackoverflow.com/questions/2045904/dependency-inject-di-friendly-library/2047657#2047657 – Mark Seemann Mar 09 '12 at 11:51

1 Answers1

0

Tell your users which classes they should add to the container. Don't forget to describe each class purpose.

jgauffin
  • 99,844
  • 45
  • 235
  • 372