Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Using Rama Krishna Vavilala's article as a reference, I have been working on developing a data repository model for use at my orgnaization and, with one exception, it works as expected. I have included a simple version of the model that illustrates the issue.
 
The question: Why do references to the DemoRepository.Devel and DemoRepository.Draft projects have to be included in the ConsoleDemo solution? It works if they are included; the type initializer throws an exception, "Could not load file or assembly [...] or one of it's dependencies.", if they aren't. This does not seem consistent with Rama's MessageBoard example. Isn't the point of the repository pattern to make the actual implementation of the individual repositories (e.g. DemoRepository.Devel and DemoRepository.Draft) invisible to the consumer (e.g ConsoleDemo)?
 

Solution: ConsoleDemo
Console Application: ConsoleDemo

Added references: DemoRepository, DemoRepository.Devel, DemoRepository.Draft)
 
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using DemoRepository;
 
namespace ConsoleDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            int demoValue = DemoSource.GetDemoValue();
 
            Console.WriteLine(demoValue);
            Console.WriteLine("...");
            Console.ReadLine(); 
        }
    }
}
 
Solution: DemoRepository
Class Library: DemoRepository

 
DemoSource.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace DemoRepository
{
    public static class DemoSource
    {
        private static IDemoRepository _Demo = CreateDemoProvider();
 
        private static IDemoRepository CreateDemoProvider()
        {
            string typeName =
                "DemoRepository.Devel.DemoProvider,DemoRepository.Devel,"+
                    "Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
                //"DemoRepository.Draft.DemoProvider,DemoRepository.Draft,"+
                    //"Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";

            Type type = Type.GetType(typeName, true);
 
            return (IDemoRepository)Activator.CreateInstance(type);
        }
 
        public static int GetDemoValue()
        {
            return _Demo.GetDemoValue();
        }
    }
}
 
IDemoRepository.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace DemoRepository
{
    public interface IDemoRepository
    {
        int GetDemoValue();
    }
}
 
Class Library: DemoRepository.Devel
Added reference: DemoRepository
 
DemoRepository.Devel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace DemoRepository.Devel
{
    public class DemoProvider : IDemoRepository
    {
        public int GetDemoValue()
        {
            return (int)12345;
        }
    }
}
 
Class Library: DemoRepository.Draft
Added reference: DemoRepository
 
DemoRepository.Draft.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace DemoRepository.Draft
{
    public class DemoProvider : IDemoRepository
    {
        public int GetDemoValue()
        {
            return (int)98765;
        }
    }
}
Posted 15-Apr-11 12:19pm
Aerryc262
Edited 18-Apr-11 7:49am
v5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In a repository frameworks (which is usually for larger projects which need agile testing) usually the repository, business model, services and presentation all will be treated as separate projects. In domain driven design the business model is the core and independent and other layers above it dependent on the model. The dependency increase towards the outer layers and the UI may directly or indirectly depend on the other layers below it. This is to make re-usability and maintenance of the core modules. So the outer layers has to add references of the inner layer projects.
 
In you case you said you had added those references. But you are not using it. You have to try with using DemoRepository; same thing for other namespaces as well. Where ever you need to access classes from other namespaces then you need to use the using keyword or else thefully qualifying name like Namespace Name.className
 
Good luck.
  Permalink  
Comments
Jeffrey Enzo at 18-Apr-11 13:08pm
   
Good solution!
Albin Abel at 19-Apr-11 14:07pm
   
Thanks Jeffrey Enzo. I given a general idea to this issue. I am not sure of the exact hierarchy of namespaces in his example. So as Henry Minute suggested Aerryc could communicate with the author of the article. That would be better.
Aerryc at 18-Apr-11 15:43pm
   
Thanks for catching the missing using DemoRepository entry in Program.cs; this is necessary to resolve the scope of the DemoSource.GetDemoValue() statement. I have updated the initial post to include this; I also changed the namespace in Program.cs from DataRepository.Core to ConsoleDemo to help reduce confusion. Unfortunately, I still have the same question.
 
When I include DemoRepository.Devel and DemoRepository.Draft as references in the ConsoleDemo project, everything works fine. In fact, this works regardless of whether or not I add using DemoRepository.Devel and using DemoRepository.Draft to the ConsoleDemo project.
 
When the repository references are not included, the exception that is returned is:
 
"Could not load file or assembly 'DemoRepository.Devel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"DemoRepository.Devel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"}
 
This appears to be a scope resoltion exception and is consistent with your explanation. Based on Rama's MessageBoard example, however, it appears that references to the individual repositories should not be necessary.
 
In his example, the consumer, MessageBoard.Web (ConsoleDemo in my example), has a reference to MessageBoard.Core (DataRepository) but not to either of the MessageBoard.DataAccess.Linq or MessageBoard.DataAccess.NonLinq repositories (DemoRepository.Devel and DemoRepository.Draft). The repositories also have a reference to MessageBoard.Core. The MessageBoard.Core project, however, does not have a reference to either the consumer or the repositories. Instead, it appears that MessageBoard.Core is only aware of a specific repository through the private CreateMessageProvider() method in MessageSource.cs (DemoSource.cs).
 
What am I missing?
Aerryc at 18-Apr-11 19:59pm
   
I believe I have found my answer and it appears that you are correct; the consumer, ConsoleDemo, must include references to the repositories DemoRepostitory.Devel and DemoRepository.Draft.
 
I spent several hours of quality time with Rama's MessageBoard example again today and found the references for the repositories listed in the property pages for his consumer, the C:\...\MessageBoard\ WebSite.
 
Again, thanks for your response.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You might get a solution more quickly if you ask your question in the messages section at the very bottom of the article you linked to.
 
Nobody should know this stuff better than Rama.
  Permalink  
Comments
Aerryc at 18-Apr-11 16:18pm
   
Ummm ... to simple? Done and thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 18 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid