The problem is it becomes very complicated to use with Ioc containers
as a string object such as name is not easy to register and the usage
becomes complicated with the Ioc container
Most good IoC containers will provide easy ways to supply constructor arguments when you do your configuration.
Your first example—constructor injection—is usually considered the preferred way. Think of your constructor as a contract to be followed, which, once satisfied, renders a valid object.
Your second code sample—property injection—is usually considered less preferable to constructor injection. Either way though, IoC containers will usually give you the ability to provide values for constructor parameters or properties at configuration, which will be supplied each time you ask your IoC to create you that object.
I'm not sure which IoC container you're looking to use, but here's a sample of code used to configure StructureMap, and provide string values for various services. Unless I'm misreading your question, this seems to be what you're looking to do.
ObjectFactory.Initialize(x =>
{
x.For<ICatalogAdminService>().Use<DLinkCatalogAdminService>()
.Ctor<string>("catalogConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_AdminConnectionString"].ConnectionString)
.Ctor<string>("contentConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_AdminConnectionString"].ConnectionString)
.Ctor<string>("webCatalogConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_WebConnectionString"].ConnectionString)
.Ctor<string>("dlinkPromotionAdminConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_AdminConnectionString"].ConnectionString);
x.For<IContentManagementAdminService>().Use<DLinkContentManagementAdminService>()
.Ctor<string>("contentConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_AdminConnectionString"].ConnectionString)
.Ctor<string>("webCatalogConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_WebConnectionString"].ConnectionString)
.Ctor<string>("dlinkPromotionConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_AdminConnectionString"].ConnectionString);
x.For<IPromotionAdminService>().Use<DLinkPromotionAdminService>()
.Ctor<string>("catalogConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_AdminConnectionString"].ConnectionString)
.Ctor<string>("promotionConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_AdminConnectionString"].ConnectionString);
x.For<ISearchService>().Use<Extractor>();
x.For<IImporter>().Use<Importer>();
x.For<IOrderAdminService>().Use<DLinkOrderAdminService>()
.Ctor<string>("contentConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_AdminConnectionString"].ConnectionString)
.Ctor<string>("orderConnectionString").Is(ConfigurationManager.ConnectionStrings["myCompany_OrdersConnectionString"].ConnectionString);
});
EDIT
Answering the comment, if you wanted to actually supply a constructor argument manually, it would look like this:
ObjectFactory.GetInstance<ICatalogAdminService>(new ExplicitArguments(
new Dictionary<string, object>() { { "parameter1", "someValue" } }));
Obviously this can get ugly fast, so you may want to whip up some factory/helper methods if you find yourself doing this often.