StructureMap Multiple Parameters

One of the common questions about IOC is how to pass parameters. This question is specially common with StructureMap since a lot of the old methods have been deprecated.

Here is a quick Example:


public class DataSource : IDataSource
{
        public DataSource(string URL, string account, string password)
        {
                     //your code here
         }

}

ObjectFactory.Initialize(x =>
{
      x.For<IDataSource>().Use<DataSource>()
           .Ctor<string>("URL").Is(URL)
           .Ctor<string>("account").Is(account)
           .Ctor<string>("password").Is(password)
           ;
}

and you can call it like this:


private IDataSource ds = ObjectFactory.GetInstance<IDataSource>();

There is a huge amount of benefits as I mentioned in my previous post, including saving a lot of typing since all parameters are preconfigured.