0

I am currently programming a ASP.NET MVC3 application, using Entity Framework 4.

There are certain tasks (processing 10K+ of records, for instance) that has to run in the background. I am writing a console application to do the job (and maybe run it as a thread or window service).

Both the console app and MVC3 EF4 project

Since I have written lots of services and model code inside the MVC3 application, I would like to reuse that in my console project.

Is that possible?

(Due to time constraint, I cannot refactor our the services into another DLL/code library)

Extrakun
  • 19,057
  • 21
  • 82
  • 129
  • why not move your services and model code into a library project that is shared between both projects. – Alastair Pitts Jun 23 '11 at 05:49
  • Time constraint. I should have done it before I got started (the client added the requirement for the batch job at the last minute and I need it like "ASAP NOW!") and I am too new to EF4 to figure out using EF4 in a code library since every tutorials and book I come across has everything in one project. – Extrakun Jun 23 '11 at 05:52

2 Answers2

2

Moving the services and model code into another DLL shouldn't take more than about 10 minutes, if that. You don't even need to change the namespaces if you don't want to - just create the new project, move the files over, add a reference to the class library from both the console project and the MVC project, and you should be done.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • A couple of quick questions - should the model generated by EF4 be in the code library? How do I set up the code library to connect to EF4? – Extrakun Jun 23 '11 at 05:54
  • @Extrakun: Do you want both projects to see the model? If so, put it in the class library... – Jon Skeet Jun 23 '11 at 19:39
2

It depends on how you have built the MVC system and which parts you are going to use in your console application.

Eg If you are going to reuse Controller logic in your console app you need to provide fake implementations of numerous classes. Eg HttpContextBase.

Further more if you have use Session, Cache, HttpContext you will have hard time using the code base for the console app.

Eranga
  • 32,181
  • 5
  • 97
  • 96