本文介绍了有人在asp.net网站上使用StructureMap吗?我有一个问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好.

我无法在StructureMap的网站上找到太多帮助,所以我希望也许可以在这里找到一些帮助.我想我的StructureMap代码中只有一个小错误,但是我不确定在哪里....

我正在尝试将Structuremap安装到我的第一个网站中,但是我无法成功引用在structuremap中设置的类.我有2个项目:c#类库(MyCompany.MySite.Core)&我的网站(MyCompany.MySite.Web).我的structuremap.config包含对我创建的名为"IRedirector"的类的引用.配置文件如下所示:

Hello.

I wasn''t able to find much help on StructureMap''s website, so I''m hoping perhaps I can find some help here. I think I have just a small bug in my StructureMap code, but I''m not sure where....

I''m trying to install structuremap into my 1st website but I''m unable to successfully reference classes set within structuremap. I have 2 projects: a c# class library (MyCompany.MySite.Core) & my website (MyCompany.MySite.Web). My structuremap.config contains a reference to a class I created called "IRedirector". The config file looks like the following:

<br /><?xml version="1.0" encoding="utf-8" ?><br /><StructureMap><br />  <Assembly Name="MyCompany.MySite.Core" /><br />  <Assembly Name="MyCompany.MySite.Web" /><br />  <PluginFamily Assembly="MyCompany.MySite.Core" Type="MyCompany.MySite.Core.Impl.IRedirector" DefaultKey="Default"/><br /></StructureMap><br />



我的IRedirector类如下所示:



My IRedirector class looks like this:

<br />namespace MyCompany.MySite.Core.Impl<br />{<br />    [PluginFamily("Default")]<br />    public interface IRedirector<br />    {<br />        /// <span class="code-SummaryComment"><summary></span><br />        ///     Sends the user to the home page.<br />        /// <span class="code-SummaryComment"></summary></span><br />        void GoToHomePage();<br /><br />        /// <span class="code-SummaryComment"><summary></span><br />        ///     Sends the user to the error page.<br />        /// <span class="code-SummaryComment"></summary></span><br />        void GoToErrorPage();<br />    }<br />}<br />



现在,据我所知,我应该能够通过引用MyCompany.MySite.Core在我的网站中引用此类,但出现错误.相反,我的网站需要MyCompany.MySite.Core.Impl.
例如,以下内容不正确:



Now, as I understood it, I should be able to reference this class in my website by referencing MyCompany.MySite.Core, but I get an error. Instead, my website wants MyCompany.MySite.Core.Impl.
For example, the following is incorrect:

<br />using MyCompany.MySite.Core;<br /><br />namespace MyCompany.MySite.Web<br />{<br />     public class Global : System.Web.HttpApplication<br />     {<br />          protected void Application_Error(object sender, EventArgs e)<br />        {<br />            IRedirector redir = ObjectFactory.GetInstance<IRedirector>();<br />            redir.GoToErrorPage();<br />        }<br />     }<br />}<br />



在该示例中,以"IRedirector"开头的行将引发错误,除非我添加对"using MyCompany.MySite"的引用.Core.Impl;"

我只想使用" MyCompany.MySite.Core来引用它.知道我在做什么错吗?

谢谢.



In that example, the line beginning with "IRedirector" will throw an error, unless I add a reference to "using MyCompany.MySite.Core.Impl;"

I want to reference it using only "MyCompany.MySite.Core". Any idea what I''m doing wrong?

Thanks.

推荐答案

Goalie35写道:
Goalie35 wrote:

我有2个项目:ac#类库(MyCompany.MySite.Core)&我的网站(MyCompany.MySite.Web).

I have 2 projects: a c# class library (MyCompany.MySite.Core) & my website (MyCompany.MySite.Web).





Goalie35写道:
Goalie35 wrote:

我的网站想要MyCompany.MySite. Core.Impl.

my website wants MyCompany.MySite.Core.Impl.





Goalie35写道:
Goalie35 wrote:

除非我添加对"using MyCompany.MySite.Core.Impl;"的引用,否则

unless I add a reference to "using MyCompany.MySite.Core.Impl;"



所有都是矛盾的陈述.您说您只有两个项目,所以MyCompany.MySite.Core.Impl是从哪里来的?如果MyCompany.MySite.Core.Impl只是项目MyCompany.MySite.Core中的名称空间,则需要在使用它的位置添加适当的名称空间包括.



All are contradictory statements. You said you have only two projects, so where does the MyCompany.MySite.Core.Impl came from? If MyCompany.MySite.Core.Impl is just a name space inside project MyCompany.MySite.Core, you need to add proper namespace includes at the place where you use it.

using MyCompany.MySite.Core;<br />using MyCompany.MySite.Core.Impl;<br /><br />namespace MyCompany.MySite.Web<br />{<br />     public class Global : System.Web.HttpApplication<br />     {<br />        /* your code goes here */<br />     }<br />}

:)

:)


这篇关于有人在asp.net网站上使用StructureMap吗?我有一个问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 03:10