ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Apesa" <vap...@hotmail.com>
Subject embeded maps in V3
Date Sat, 17 Jan 2009 00:10:59 GMT
In case anyone wants to know, I found the solution for loading maps files from a DLL in V3.
I looked in the UnitTests. I did not immediately find it since  a lot of the class names have
changed. Here is some example code for creating an IDataMapper:


=============================

  string uri = "assembly://MyApp/Config/SqlMap.config";
  IResource resource = ResourceLoaderRegistry.GetResource(uri);

  IConfigurationEngine engine = new DefaultConfigurationEngine();
  engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

  IMapperFactory mapperFactory = engine.BuildMapperFactory();
  mapper = ((IDataMapperAccessor)mapperFactory).DataMapper;

=============================

cheers,
Vince


  ----- Original Message ----- 
  From: Christopher DeGuise 
  To: user-cs@ibatis.apache.org 
  Sent: Wednesday, January 14, 2009 8:06 PM
  Subject: Re: file paths for config files in n-tier architecture


  The way I handled this was to use the code from Example 4.4 and drive all IBatis request
through the custom mapper. In addition I altered the InitMapper method to look something like
this:

  DomSqlMapBuilder builder = new DomSqlMapBuilder();
  XmlDocument sqlMapConfig = Resources.GetEmbeddedResourceAsXmlDocument("fully.qualified.embedded.resource.SqlMap.config,
SomeAssembly");
  _Mapper = builder.Configure(sqlMapConfig);       

  Make sure you mark your config files as embedded resources. With my projects I do not ship
any raw .xml/.config files, they are all bundled inside a library.

  Hope that helps.
  Chirs



  On Wed, Jan 14, 2009 at 11:06 AM, Robin Silver <robin@sharedevent.com> wrote:

    Hey all,



    I have 4 facets to my application, Web, Test, Services, Data.  



    Web – the website

    Test – the token test project… ;)

    Services – interface between web and underlying persistence layer (and additional services)

    Data – my data model, POCO's etc.



    Assume the scenario where there is a "List All Customer's" button on my page.  



    Admin User clicks it and web calls CustomerService.ListAllCustomers().  This in turn calls
the iBatis structure sort of like…



    ArrayList al = (ArrayList)Mapper.Instance().QueryForList("SelectAll", null);

                

    The SqlMap.config and CustomerMapping.xml files are in my Services project.  



    When I run this, I get the error: 



    Unable to load file via resource "SqlMap.config" as resource. Cause : Could not find file
'C:\Projects\TestProject\TestProject.Web\SqlMap.config'.



    It seems to want to load the config from the calling project (web), not the project in
which the actual code resides(services).  When I look at the NPetStore example, the config
files are in the web also. 



    My question is, is there any way to configure it to look for files in the services project
instead?  I don't want to have any reference to IBatis in my Web if at all possible.



    Thx,

    Rob

Mime
View raw message