1

I am currently working on a ASP.NET project in .NET framework 4.5, using Entity Framework, and working in Visual Studio Express 2012 for web. At this point, I have created a lot of models, context and controllers.

I have also made some classes for importing huge amounts of data into the database from data files. However, at this point it has become clear that the actual import should probably be done through a service or console application.

How do I go about separating the importer code logic from the current project, while retaining all the dependencies to the MVC framework, to put it into a console application project?

  • Do I just make the new project depend on the old one?
  • The connection string for the database is configured through web.config, and managed by the internal context logic in the old project. How do I use this is the console application?
Harold Smith
  • 882
  • 3
  • 12
  • 21

1 Answers1

3

Ideally, your business logic is separate from your UI, which in this case is your ASP.NET website. Within Visual Studio, I would separate all that data logic into it's own project that's set up as a class library, have the web project depend on/reference it. Then you can add another console/service application project to the solution and reference the very same objects.

http://msdn.microsoft.com/en-us/magazine/dd419654.aspx http://en.wikipedia.org/wiki/Separation_of_concerns

Nathan Loding
  • 3,185
  • 2
  • 37
  • 43
  • Yup, and that is essentially what I want to do. And it seems to be working just fine. I did, however, need to copy the web.config file into the console application project, renaming it app.config. Is there a way to share config files between projects? – Harold Smith Jul 27 '13 at 00:17
  • You can - http://stackoverflow.com/questions/2746797/c-can-we-share-some-contents-of-app-config-between-projects and http://blogs.msdn.com/b/jjameson/archive/2009/04/02/linked-files-in-visual-studio-solutions.aspx – Nathan Loding Jul 27 '13 at 00:19
  • Great tip, though, adding as link doesn't work in my case, as it is necessarily called web.config in one location and app.config in the other. There doesn't seem to be an option to rename the link. – Harold Smith Jul 27 '13 at 01:54