Integration of Repository with Smart Client Factory

Oct 23, 2007 at 8:58 PM
Hi

I am trying to integrate Smart Client Software Factory with Repository Factory. But getting an exception Here is what am doing:
- Set the Project responsibility through Guidance Automation Extension, created Database connection, business entities.
- Created View Presenter classes through Smart Client
- When I tried to call the repository from the presenter class like
IUserGroupRepository repository = RepositoryFactory.Create<IUserGroupRepository>();
userGroup = repository.GetUserGroupByID(userID);
am getting an exception in the first line. The Excetion is "Exception of type 'System.Configuration.ConfigurationErrorsException' was thrown.".

Please guide me on the same.

Thanks in advance.

Gnan
Coordinator
Oct 24, 2007 at 6:46 AM
Edited Oct 24, 2007 at 6:47 AM
Hi Gnan,

Make sure that you have the connection string and repositoryFactory config sections in your app.config file. The Repository Factory adds them automatically for you.

I think the problem you are having is the same as described in the discussion proper way to instantiate repository classes.

In a summary, if you want to use:
  • IUserGroupRepository repository = RepositoryFactory.Create<IUserGroupRepository>();
Then, you will need to specify the default database in your app config:
  • <dataConfiguration defaultDatabase="ConnectionString" />
Otherwise, you can just pass the connection string to the Create method:
  • IUserGroupRepository repository = RepositoryFactory.Create<IUserGroupRepository>("ConnectionString");

I hope this helps.

Thanks,
Luis
Oct 24, 2007 at 2:36 PM
Luis,

I have already included the Default Database in the App.config and the configuration file is OK.

I tried giving the ConnectionString in the repository Create method too. But not able to succeed.

I am not able to figure out the issue. Please guide me.

Thanks in advance.

Gnan
Oct 24, 2007 at 4:45 PM

gnanforu wrote:
Luis,

I have already included the Default Database in the App.config and the configuration file is OK.

I tried giving the ConnectionString in the repository Create method too. But not able to succeed.

I am not able to figure out the issue. Please guide me.

Thanks in advance.

Gnan


Could you please post your app.config file?

You need more than just the connection string - you need the repository factory section that maps the interface to the concrete repository implementation.

-Chris
Oct 24, 2007 at 5:39 PM
Edited Oct 24, 2007 at 5:41 PM
Here is my config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="repositoryFactory" type="Microsoft.Practices.Repository.Configuration.RepositoryFactorySection, Microsoft.Practices.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<dataConfiguration defaultDatabase="BARRConnectionString" />
<connectionStrings>
<add name="BARRConnectionString" connectionString="Data Source=GNANPC;Initial Catalog=BRR;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<repositoryFactory>
<repositories>
<add interfaceType="SmartClient.APModule.IUserGroupRepository, APModule" repositoryType="SmartClient.APModule.UserGroupRepositoryArtifacts.UserGroupRepository, APModule" />
</repositories>
</repositoryFactory>
</configuration>
----------------------------------------------------------------------------------------------------------------------------
Coordinator
Oct 24, 2007 at 9:11 PM
Gnan,

From your config file, I see that you created the repository in the APModule, and this is the config file of APModule.

I am just wondering if these settings should be in the app config of the Shell module. Could you please try that to see if this is the problem?

Thanks,
Luis
Oct 26, 2007 at 2:26 PM
Edited Oct 26, 2007 at 2:26 PM
Sorry, It didn't help. Any other suggestion?

Thanks
Gnan
Nov 22, 2007 at 10:52 PM
I´m having the same type of problems integrating Smart Client Software Factory with Repository Factory, but I'm registering de repositories as services, where should I put the <dataConfiguration defaultDatabase="ConnectionString" /> element on the shell project app.config file ?
Under <repositoryFactory>? I suppose, not as shown on the post above.

This is the exception I´m getting

Microsoft.Practices.CompositeUI.Services.ModuleLoadException was unhandled
Message="Failed to load module from assembly b33fb2fb-6a5e-43fe-a268-abed1adfb485. Error was:\r\nFailed to load module from assembly Pos, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. Error was:\r\nNo se puede crear cadenas sin inicializar."
Source="Infrastructure.Library"
StackTrace:
en PetClubPos.Infrastructure.Library.Services.DependentModuleLoaderService.ModuleMetadata.ThrowModuleLoadException(Exception innerException) en C:\Wrk\Nestle\PetClub\PetClubPos\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:línea 434
en PetClubPos.Infrastructure.Library.Services.DependentModuleLoaderService.ModuleMetadata.InitializeModuleClasses(WorkItem workItem) en C:\Wrk\Nestle\PetClub\PetClubPos\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:línea 396
en PetClubPos.Infrastructure.Library.Services.DependentModuleLoaderService.InnerLoad(WorkItem workItem, IModuleInfo[] modules) en C:\Wrk\Nestle\PetClub\PetClubPos\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:línea 124
en PetClubPos.Infrastructure.Library.Services.DependentModuleLoaderService.Load(WorkItem workItem, IModuleInfo[] modules) en C:\Wrk\Nestle\PetClub\PetClubPos\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:línea 79
en Microsoft.Practices.CompositeUI.CabApplication`1.LoadModules()
en Microsoft.Practices.CompositeUI.CabApplication`1.Run()
en PetClubPos.Infrastructure.Shell.ShellApplication.RunInDebugMode() en C:\Wrk\Nestle\PetClub\PetClubPos\Source\Infrastructure\Shell\ShellApplication.cs:línea 60
en PetClubPos.Infrastructure.Shell.ShellApplication.Main() en C:\Wrk\Nestle\PetClub\PetClubPos\Source\Infrastructure\Shell\ShellApplication.cs:línea 51
en System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
en System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
en Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
en System.Threading.ThreadHelper.ThreadStart_Context(Object state)
en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
en System.Threading.ThreadHelper.ThreadStart()

and this is my Shell app.config

<configuration>
<configSections>
<section name="repositoryFactory" type="Microsoft.Practices.Repository.Configuration.RepositoryFactorySection, Microsoft.Practices.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>

<connectionStrings>
<add name="PetClubLocal" connectionString="Data Source=.;Initial Catalog=PetClubLocal;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<repositoryFactory>
<dataConfiguration defaultDatabase="PetClubLocal" />

<repositories>
<add interfaceType="PetClubPos.DataAccess.ICategoriaRepository, PetClubPos.DataAccess" repositoryType="PetClubPos.DataAccess.BusinessEntities.CategoriaRepositoryArtifacts.CategoriaRepository, PetClubPos.DataAccess" />
<add interfaceType="PetClubPos.DataAccess.IDetalleVentaRepository, PetClubPos.DataAccess" repositoryType="PetClubPos.DataAccess.BusinessEntities.DetalleVentaRepositoryArtifacts.DetalleVentaRepository, PetClubPos.DataAccess" />
<add interfaceType="PetClubPos.DataAccess.IMedioPagoRepository, PetClubPos.DataAccess" repositoryType="PetClubPos.DataAccess.BusinessEntities.MedioPagoRepositoryArtifacts.MedioPagoRepository, PetClubPos.DataAccess" />
<add interfaceType="PetClubPos.DataAccess.IProductoRepository, PetClubPos.DataAccess" repositoryType="PetClubPos.DataAccess.BusinessEntities.ProductoRepositoryArtifacts.ProductoRepository, PetClubPos.DataAccess" />
<add interfaceType="PetClubPos.DataAccess.IVendedorRepository, PetClubPos.DataAccess" repositoryType="PetClubPos.DataAccess.BusinessEntities.VendedorRepositoryArtifacts.VendedorRepository, PetClubPos.DataAccess" />
<add interfaceType="PetClubPos.DataAccess.IVentaRepository, PetClubPos.DataAccess" repositoryType="PetClubPos.DataAccess.BusinessEntities.VentaRepositoryArtifacts.VentaRepository, PetClubPos.DataAccess" />
</repositories>
</repositoryFactory>
Jan 16, 2008 at 10:21 PM
Edited Jan 16, 2008 at 10:59 PM
Microsoft.Practices.Repository.Configuration.RepositoryElementCollection.RepositoryElement this[Type key] does not seem to be finding the RepositoryTypes I created. The line below always returns null.
Type currentType = Type.GetType(element.InterfaceType);

I have been working through the Labs and the Repository Factory Screencast to create a new Web Client Solution using Repository Factory. I have two Foundational Models (DataAccessLayer, BusinessLayer), and 2 business modules (payroll, administration).

Is it that the correct dll is not being loaded in order to create the correct data type or could it be that my problem is related to the layout of the modules in the website, or is there something else I am missing?


I am using:
Studio 2005
Repository Factory - Change Set 14968
Web Client Guidance Package Bundle - October 2007
Enterprise Library May 2007

Snipped from web.config:
....
</sectionGroup>
<section name="repositoryFactory" type="Microsoft.Practices.Repository.Configuration.RepositoryFactorySection, Microsoft.Practices.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</configSections>
<appSettings/>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=FRODO\SQLEXPRESS;Initial Catalog=dev;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

...
<repositoryFactory>
<repositories>
<add interfaceType="BackOffice.DataAccessLayer.IEmployeeRepository, DataAccessLayer" repositoryType="BackOffice.DataAccessLayer.BusinessLayer.EmployeeRepositoryArtifacts.EmployeeRepository, DataAccessLayer"/>
</repositories>
</repositoryFactory>
</configuration>


Stack Trace:

Source Error:


Line 18: if (employees == null)
Line 19: {
Line 20: IEmployeeRepository employeeRepository = RepositoryFactory.Create<IEmployeeRepository>("ConnectionString");
Line 21: employees = employeeRepository.GetAllFromEmployee();


Source File: E:\Projects\BackOffice\Payroll\PayrollController.cs Line: 20

Stack Trace:


ConfigurationErrorsException: Exception of type 'System.Configuration.ConfigurationErrorsException' was thrown.
Microsoft.Practices.Repository.RepositoryFactory.GetRepositoryType(Type repositoryInterface) +209
Microsoft.Practices.Repository.RepositoryFactory.Create(Type repositoryInterface, String connectionStringName) +186
Microsoft.Practices.Repository.RepositoryFactory.Create(String connectionStringName) +98
BackOffice.Payroll.PayrollController.get_Employees() in E:\Projects\BackOffice\Payroll\PayrollController.cs:20
BackOffice.Payroll.PayrollController.GetEmployees() in E:\Projects\BackOffice\Payroll\PayrollController.cs:38
BackOffice.Payroll.Views.EmployeeListPresenter.OnViewLoaded() in E:\Projects\BackOffice\Payroll\Views\EmployeeListPresenter.cs:25
BackOffice.Payroll.Views.EmployeeList.Page_Load(Object sender, EventArgs e) in e:\Projects\BackOffice\WebSites\DevelopmentWebsite\Payroll\EmployeeList.aspx.cs:18
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7248
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.payrollemployeelistaspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\developmentwebsite\ee2e15b0\d70730ca\AppWebdnmqqup4.0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64


Jan 17, 2008 at 4:43 PM
I have found the issue.
The code generation put the following in my web.config file.

<repositories>
<add interfaceType="BackOffice.DataAccessLayer.IEmployeeRepository, DataAccessLayer" repositoryType="BackOffice.DataAccessLayer.BusinessLayer.EmployeeRepositoryArtifacts.EmployeeRepository, DataAccessLayer"/>

It should have been:

<repositories>
<add interfaceType="BackOffice.DataAccessLayer.Interfaces.IEmployeeRepository, DataAccessLayer" repositoryType="BackOffice.DataAccessLayer.BusinessLayer.EmployeeRepositoryArtifacts.EmployeeRepository, DataAccessLayer"/>

The interface code must have been repackaged and the config file generation was overlooked. I manually changed the web.config file and it fixed it.
Jun 23, 2008 at 10:57 PM

Nice find!!

I hope this is in Issue tracker.

Payur

 


tom_howard wrote:
I have found the issue.
The code generation put the following in my web.config file.

<repositories>
<add interfaceType="BackOffice.DataAccessLayer.IEmployeeRepository, DataAccessLayer" repositoryType="BackOffice.DataAccessLayer.BusinessLayer.EmployeeRepositoryArtifacts.EmployeeRepository, DataAccessLayer"/>

It should have been:

<repositories>
<add interfaceType="BackOffice.DataAccessLayer.Interfaces.IEmployeeRepository, DataAccessLayer" repositoryType="BackOffice.DataAccessLayer.BusinessLayer.EmployeeRepositoryArtifacts.EmployeeRepository, DataAccessLayer"/>

The interface code must have been repackaged and the config file generation was overlooked. I manually changed the web.config file and it fixed it.



Aug 12, 2008 at 7:02 AM
Hi,

Did someone actually solve gnanforu's initial problem?

I'm getting the same issue and have tried all the 'solutions' and none of them worked.

My config file looks as follows....

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="repositoryFactory" type="Microsoft.Practices.Repository.Configuration.RepositoryFactorySection, Microsoft.Practices.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />    
    </configSections>
    <connectionStrings>
        <add name="MyConnection" connectionString="Data Source=SEB2\SQLEXPRESS;Initial Catalog=DB1;Integrated Security=True" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <repositoryFactory>
        <repositories>
            <add interfaceType="DataAccess.IAccountRepository, DataAccess" repositoryType="DataAccess.BusinessEntities.AccountRepositoryArtifacts.AccountRepository, DataAccess" />
            <add interfaceType="DataAccess.IGroupRepository, DataAccess" repositoryType="DataAccess.BusinessEntities.GroupRepositoryArtifacts.GroupRepository, DataAccess" />
            <add interfaceType="DataAccess.IGroupProcessLinkRepository, DataAccess" repositoryType="DataAccess.BusinessEntities.GroupProcessLinkRepositoryArtifacts.GroupProcessLinkRepository, DataAccess" />
            <add interfaceType="DataAccess.IProcessRepository, DataAccess" repositoryType="DataAccess.BusinessEntities.ProcessRepositoryArtifacts.ProcessRepository, DataAccess" />
        </repositories>
    </repositoryFactory>
    <dataConfiguration defaultDatabase="MyConnection" />
</configuration>


Any help would be great


 

Coordinator
Aug 13, 2008 at 5:10 AM
Edited Aug 13, 2008 at 5:29 AM
Hi seb666,

Please try using the app.config below. I made some changes to it (see text in bold).

I noticed two problems:

1. The dataConfiguration section definition is missing. In order to use <dataConfiguration defaultDatabase="MyConnection" />, you will need to define dataConfiguration in configSections as shown below.

2. The repository interfaces are created under the Interfaces directory. As mentioned above, there was an issue with the generated app.config missing the Interfaces directory (Work Item # 9218). This issue has been fixed since Change Set #20330, and it looks like you are using an older version. The workaround as mentioned above is to change the interfaceType as shown below in bold. The important thing is that the interfaceType must match the interface name including its namespace, so you can also check in your source code files to make sure it is right.

I hope this will solve your problem. If not, please let me know what version of Repository Factory you are using and the exactly exception/error you are getting. Additionally, if you could send me the your source files would help as well.

Cheers,
Luis

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="repositoryFactory" type="Microsoft.Practices.Repository.Configuration.RepositoryFactorySection, Microsoft.Practices.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
  </configSections>
  <connectionStrings>
    <add name="MyConnection" connectionString="Data Source=SEB2\SQLEXPRESS;Initial Catalog=DB1;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <repositoryFactory>
    <repositories>
      <add interfaceType="DataAccess.Interfaces.IAccountRepository, DataAccess" repositoryType="DataAccess.BusinessEntities.AccountRepositoryArtifacts.AccountRepository, DataAccess" />
      <add interfaceType="DataAccess.Interfaces.IGroupRepository, DataAccess" repositoryType="DataAccess.BusinessEntities.GroupRepositoryArtifacts.GroupRepository, DataAccess" />
      <add interfaceType="DataAccess.Interfaces.IGroupProcessLinkRepository, DataAccess" repositoryType="DataAccess.BusinessEntities.GroupProcessLinkRepositoryArtifacts.GroupProcessLinkRepository, DataAccess" />
      <add interfaceType="DataAccess.Interfaces.IProcessRepository, DataAccess" repositoryType="DataAccess.BusinessEntities.ProcessRepositoryArtifacts.ProcessRepository, DataAccess" />
    </repositories>
  </repositoryFactory>
  <dataConfiguration defaultDatabase="MyConnection" />
</configuration>

Aug 15, 2008 at 1:44 AM
Hi Luis,

I've tried all that again with no success. I was using the 10/2007 release that is on the front page, but am now using the 07/2008 for VS2008 release you have placed up in the releases section. I have started a simple project to try minimise any possible external factors but still get the same error. It looks like the release I have downloaded still has the issue with the incorrect config (missing the interfaces namespace) and am now wondering if I still haven't got the latest version? If I havn't can you direct me to where I should get the latest version from, as I can't seem to find a newer one than the 07/2008 release.

Below is my new config file and the code to call the factory.....

Any help would be fantastic.

<?

xml version="1.0" encoding="utf-8"?>
<
configuration>
<
configSections>
<
section name="repositoryFactory" type="Microsoft.Practices.Repository.Configuration.RepositoryFactorySection, Microsoft.Practices.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<
section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
</
configSections>
<
connectionStrings>
<
add name="MyConnection" connectionString="Data Source=SEB\SQLEXPRESS;Initial Catalog=DB1;Integrated Security=True" providerName="System.Data.SqlClient" />
</
connectionStrings>
<
repositoryFactory>
<
repositories>
<
add interfaceType="DataAccess.Interfaces.IAccountRepository, DataAccess" repositoryType="DataAccess.AccountRepositoryArtifacts.AccountRepository, DataAccess" />
</
repositories>
</
repositoryFactory>
<
dataConfiguration defaultDatabase="MyConnection" />
</
configuration>


 

using

System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.Repository;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

 

 

private void button1_Click(object sender, EventArgs e)
{
DataAccess.BusinessEntities.
Account x = new DataAccess.BusinessEntities.Account();
x.Account_Id = 1;
x.Name =
"Boo";
x.Deactivated_flag =
false;

DataAccess.Interfaces.
IAccountRepository repository = RepositoryFactory.Create<DataAccess.Interfaces.IAccountRepository>();
repository.Add(x);
}
}
}

 

Aug 15, 2008 at 2:31 AM

Okay I've got it working.

Two important things you need to know....

First, get the latest source from the source section and build it your self so you can debug into it if you need it.

Second, if you have your data access in a seperate assembly like I do you need to copy the app.config into the assembly that calls the RepositoryFactory.Create otherwise it can't find the respostoryFactory section in the config files and throws the error we have all been getting.

Kind of important details......

Thanks for your help Luis.