开发者

Injecting Subsonic SimpleRepository class to controller

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开发者_C百科("System.Web.Mvc.Html");
        ViewEngines.Engines.Clear();
        ViewEngines.Engines.Add(new SparkViewFactory(sparkSettings));
    }

Any help would be appreciated! Thanks!


The problem is that StructureMap was using the constructor with the most parameters, I fixed with this:

 ObjectFactory.Configure(
            x => { x.SelectConstructor<SimpleRepository>(() => new SimpleRepository()); });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜