English 中文(简体)
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("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()); });
问题回答

暂无回答




相关问题
Structuremap (or any IoC, really) architecture question

I m going to use structuremap for a project I m working on. The basic gist is that I have a repository pattern with an NHibernate implementation, but I want to use StructureMap to load the ...

Inject static property with StructureMap?

is it possible inject static property, like I do below, because it does not work for me? public static IMerchantModule MerchantModule { get; set; } public RequestBaseValidationRules() { ...

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 ...

StrucutureMap RhinoMock Record/Playback, Example needed

I m looking for some examples on how to do the following Mock Tests using StructureMap or Unity with NUnit. I have the following code structure public interface IDAL { List<Model> Method1(...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

热门标签