浏览:208 2008-07-18 16:20 来自 【组长】JackLee      :

接口:

namespace ServiceInterfaces
{
  public interface IPerson:IServiceInterface
    {
        Person[] GetAllPerson();
        Person GetPersonByID(string  PersonID);
    }
}

接口实现:

namespace ServiceImpls
{
    public class PersonService:ServiceInterfaces .IPerson
    {
        public Person[] GetAllPerson()
        {
            return Gateway.Default.FindArray<Person>();
        }
        public Person GetPersonByID(string  PersonID)
        {
            return Gateway.Default.Find<Person>(PersonID);
        }
    }
}

服务工厂:

public abstract class SeviceFactory
{
    private static NBear.IoC.Service.ServiceFactory factory = NBear.IoC.Service.ServiceFactory.Create();
    public static IServiceInterFaceType GetService<IServiceInterFaceType>() where IServiceInterFaceType:IServiceInterface
    {
        return factory.GetService<IServiceInterFaceType>();
    }
}

页面调用:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ServiceInterfaces.IPerson ps = SeviceFactory.GetService<ServiceInterfaces.IPerson>();
        this.Chjw.DataSource = ps.GetAllPerson();
        this.Chjw.DataBind();
    }
}

Web.config:

<?xml version="1.0"?>

<configuration>
 <configSections>
  <section name="entityConfig" type="NBear.Common.EntityConfigurationSection, NBear.Common"/>
    <section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/>
 </configSections>
 <entityConfig>
  <includes>
   <add key="Sample Entity Config" value="~/EntityConfig.xml"/>
  </includes>
 </entityConfig>
  <castle>
    <components>
 
      <component id="category service" service="ServiceInterfaces.IPerson, ServiceInterfaces" type="ServiceImpls.PersonService, ServiceImpls"/>
    </components>
  </castle>

  <appSettings/>
 <connectionStrings>
  <add name="DbConn2005" connectionString="Data Source=.;Initial Catalog=Student;Integrated Security=True" providerName="NBear.Data.SqlServer9.SqlDbProvider9"/>
 </connectionStrings>
 <system.web>
 
  <compilation debug="true">
   <assemblies>
    <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>

  <authentication mode="Windows"/>
  </system.web>
</configuration>

问题是:

“SeviceFactory”的类型初始值设定项引发异常。

 

收藏 楼主
  2个月前 【组长】 JackLee      :
怎么没有解答呀!!
1楼 回到顶楼 
  2个月前  阿不      :
具体的异常信息?
2楼 回到顶楼 
  2个月前 【组长】 JackLee      :
用户代码未处理 System.TypeInitializationException
Message="“SeviceFactory”的类型初始值设定项引发异常。"
Source="App_Code.68rgwpbv"
TypeName="SeviceFactory"
StackTrace:
在 SeviceFactory.GetService[IServiceInterFaceType]()
在 _Default.Page_Load(Object sender, EventArgs e) 位置 e:\C#练习\NBearStudy\Default.aspx.cs:行号 20
在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
在 System.Web.UI.Control.OnLoad(EventArgs e)
在 System.Web.UI.Control.LoadRecursive()
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
3楼 回到顶楼 
  2个月前  阿不      :
public abstract class SeviceFactory

这里不要使用抽象类。。。
4楼 回到顶楼 
  2个月前 【组长】 JackLee      :
@阿不
去掉抽象关键字(abstract)后,异常还是一样的,下面是堆栈跟踪信息:你有看我的配置方件没有中呀,是不是配置有问题呀????
堆栈跟踪:
[ConfigurationException: The type name ServiceImpls.PersonService, ServiceImpls could not be located]
Castle.Windsor.Installer.DefaultComponentInstaller.ObtainType(String typeName) +149
Castle.Windsor.Installer.DefaultComponentInstaller.SetUpComponents(IConfiguration[] configurations, IWindsorContainer container) +293
Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store) +88
Castle.Windsor.WindsorContainer.RunInstaller() +92
Castle.Windsor.WindsorContainer..ctor(IConfigurationInterpreter interpreter) +162
NBear.IoC.Service.SimpleServiceContainer.Init(IServiceMQ mq, IDictionary serviceKeyTypes) in c:\Teddy\NBearV3\src\NBear.IoC\Service\SimpleServiceContainer.cs:46
NBear.IoC.Service.SimpleServiceContainer..ctor() in c:\Teddy\NBearV3\src\NBear.IoC\Service\SimpleServiceContainer.cs:155
NBear.IoC.Service.ServiceFactory.Create() in c:\Teddy\NBearV3\src\NBear.IoC\Service\ServiceFactory.cs:280
SeviceFactory..cctor() in e:\C#练习\NBearStudy\App_Code\SeviceFactory.cs:16

[TypeInitializationException: “SeviceFactory”的类型初始值设定项引发异常。]
SeviceFactory.GetService() in e:\C#练习\NBearStudy\App_Code\SeviceFactory.cs:20
_Default.Page_Load(Object sender, EventArgs e) in e:\C#练习\NBearStudy\Default.aspx.cs:20
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +31
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +68
System.Web.UI.Control.OnLoad(EventArgs e) +88
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3035


5楼 回到顶楼 
  2个月前 【组长】 JackLee      :
问题找到了:需要将接口实现的程序集Copy到网站目录下!!
6楼 回到顶楼 

注册用户登录后才能回复,登录注册
> 返回“郑州Net俱乐部”


其他话题

相关内容

相关链接

1 24811