开发者

AutoWiring with StructureMap, Constructor Injection

I'm new to structuremap. :))

I have a class which implements IPresenter :

public class SoldierPresenter : IPresenter
{
...
public SolierPresenter(ISoldierView soldierView)
{

}
...
}

When I call :

var presenters = ObjectFactory.GetAllInstances<IPresenter>();

I get zero instances... what am i missing?!

Here is the configuration code for the container:

  Scan(
            scanner =>
                {
                    scanner.AssemblyContainingType(typeof(IShell));
                    scanner.WithDefaultConventions();

                    scanner.TheCallingAssembly();
                    scanner.AddAllTypesOf<IPresent开发者_开发知识库er>();

                    scanner.WithDefaultConventions();
                });

Thanks in advance, Erik.

Container.WhatDoIHave(); Shows the following:

IPresenter (DutyManager.Presentation.Framework.IPresenter) DutyManager.Presentation.SoldiersPresenter, DutyManager.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Configured DutyManager.Presentation.SoldiersPresenter, DutyManager.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Scoped as: PerRequest


ISoldiersView (DutyManager.Presentation.ISoldiersView) DutyManager.Presentation.SoldiersView, DutyManager.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null DutyManager.Presentation.SoldiersView, DutyManager.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Scoped as: PerRequest


Your code sample does not provide enough information. Are you configuring the container owned by ObjectFactory, or are you creating your own instance of Container? ObjectFactory can only access its own Container.

You are trying to call GetAllInstances on ObjectFactory, but you call WhatDoIHave on Container. It is not clear which container you are configuring with the "Scan" statement you included.

Using the code you provided (and assuming use of ObjectFactory throughout), I was not able to reproduce your issue. Make sure you are consistently using the same container.

If that doesn't solve your problem, you might consider posting to the StructureMap mailing list, where it will get a lot more attention from StructureMap users.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜