Injecting Subsonic SimpleRepository class to controller
Posted
by ryudice
on Stack Overflow
See other posts from Stack Overflow
or by ryudice
Published on 2009-11-22T20:20:53Z
Indexed on
2010/05/18
5:50 UTC
Read the original article
Hit count: 423
Hi, I'm tryingot get started with IoC, I have an MVC project in which is use subsonic, I'm trying to inject subsonic simplerepository to my controllers but I'm getting this error: StructureMap Exception Code: 205 Missing requested Instance property "connectionStringName" for InstanceKey "60b735fb-0a7f-4eb4-be04-635f6f32233d"
Here is my registry class:
public class RepositoryRegistry : Registry
{
protected override void configure()
{
ForRequestedType<IRepository>().TheDefault.Is.OfConcreteType(typeof(SimpleRepository));
}
}
And here is my controller factory:
public class StoreControllerFactory: DefaultControllerFactory
{
protected override IController GetControllerInstance(Type controllerType)
{
IController result = null;
if (controllerType!=null)
{
result = ObjectFactory.GetInstance(controllerType) as Controller;
}
return result;
}
}
And this is how I configure StructureMap:
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
ObjectFactory.Initialize(x=>
{
x.AddRegistry(new RepositoryRegistry());
});
ControllerBuilder.Current.SetControllerFactory(new StoreControllerFactory());
var sparkSettings = new SparkSettings().SetDebug(true).AddNamespace("System.Web.Mvc.Html");
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new SparkViewFactory(sparkSettings));
}
Any help would be appreciated! Thanks!
© Stack Overflow or respective owner