0

In MVC 2 I am working on something and have ran into a snag. I got my repository put instead of putting in the same class the interface is I have it same project as the EDMX file.

Initializing StructureMap is what's killing me at this point. Here's where I'm initizing StructureMap (in Global.asax.cs.)

ObjectFactory.Initialize(x =>
    {
        x.ForRequestedType<IUnitOfWorkFactory>()
            .TheDefaultIsConcreteType<EFUnitOfWorkFactory>()
            .CacheBy(InstanceScope.HttpContext);

        x.ForRequestedType(typeof(IRepository<>))
            .CacheBy(InstanceScope.HttpContext)
            .TheDefaultIsConcreteType(typeof(GenericRepository<>));
    });

The Namespace for this project is GpdsCreationTaxidermy.Data (which is the same Namespace as my GenericRepository.cs). I would post the code for this file but I dont believe that is the problem here. In my Global.asax I import the proper Namespace

using GodsCreationTaxidermy.Data;

The error I'm getting is:

Error 3 The type or namespace name 'GenericRepository' could not be found (are you missing a using directive or an assembly reference?)

Also attached is an image showing this particular projects layout

enter image description here

Can someone help with this issue, or what I'm doing wrong here

EDIT I have even tried adding GodsCreationTaxidermy.Data to the file name and still no luck.

PsychoCoder
  • 10,570
  • 12
  • 44
  • 60
  • That red tick in your screenshot indicates unsaved changes to the project - is that causing your problem? – JK. May 19 '11 at 01:46
  • I thought that as well but same happens after changes were saved – PsychoCoder May 19 '11 at 01:48
  • Did you do the usual dance of "clean solution and rebuild" and "quit visual studio, (optionally) restart your machine cause you never know with this bloody thing, clean solution, rebuild"? – Adam Lear May 19 '11 at 01:54
  • Also, don't know much about StructureMap, but does [this](http://structuremap.net/structuremap/Generics.htm) or [this](http://stackoverflow.com/questions/3817187/how-do-i-use-structuremap-with-generic-unclosed-types-using-scan-with-a-greedy) help at all? – Adam Lear May 19 '11 at 01:57
  • Yeah I did the normal clean & rebuild and noting has resolved this yet. I'll look through those links you provided. – PsychoCoder May 19 '11 at 02:04

2 Answers2

1

Thanks for sending the files :-)

It looks like the definition of GodsCreationTaxidermy.Data has changed.

This is what I did to fix the problem:

Remove these references from GodsCreationTaxidermy.Data.Repository Class Library:

  • GodsCreationTaxidermy.Data
  • GodsCreationTaxidermy.Data.Repository

Remove these references from GodsCreationTaxidermy.Data Class Library:

  • GodsCreationTaxidermy
  • GodsCreationTaxidermy.Data

Remove the reference to GodsCreationTaxidermy.Data in the GodsCreationTaxidermy MVC project and re-add the reference, choosing GodsCreationTaxidermy.Data from the Project tab

Hopefully that'll get the GenericRepository working :-)

I did notice that the following line no longer works though:

EFUnitOfWorkFactory.SetObjectContext(() => new GodsCreationTaxidermyEntities());

GodsCreationTaxidermyEntities doesn't seem to exist in GodsCreationTaxidermy.Data any more. Does that cause you an issue?

Kev Ritchie
  • 1,599
  • 10
  • 16
0

Try this:

.TheDefaultIsConcreteType(typeof(GodsCreationTaxidermy.Data.GenericRepository<>));

Possibly remove <> after GenericRepository. Has GodsCreationTaxidermy.Data been added to the MVC site as a reference?

Kev Ritchie
  • 1,599
  • 10
  • 16
  • Thanks for the try, but I had already tried that way as well (It makes sense, and sounds like it should work, but it doesn't) As for removing the <>'s Those have to be there since the signature of the repository is GenericReposity – PsychoCoder May 19 '11 at 22:25