0

I have written a MVC web application that is used on our corporate intranet. We also have an MVC web site that is a seperate web application that is used by our customers. For our website to talk to our intranet systems database I have written a c# web service to access it.

The problem I have now is in the intranet application I have a complex routine that does some calculations that I now need in the web service for the website to do the same thing. I do not want to copy the logic and have it repeated in 2 locations for obvious reasons, so I need the web service and web application to share the same code base. I know this is possible but what is the best was to go about the use of application variables stored in web config files. For example if I move the code out of the intranet app and into a class library I will loose the functionality of being able to access the webconfig file, so where do I put these variables?

Any Suggestions on the best way to do this?

1
  • 1
    why not use database for the configuration? and moving out the functionality to class library. Commented Sep 25, 2012 at 13:41

2 Answers 2

1

I will loose the functionality of being able to access the webconfig file, so where do I put these variables?

You won't loose that ability. Every part of your application can access the configuration file, for instance by using the ConfigurationManager.AppSettings property.

Sign up to request clarification or add additional context in comments.

1 Comment

Of course the real question is whether deep parts of your application should interact with the configuration file :-)
0

Put the shared code in a class library that is referenced from both the web site and the web service.

2 Comments

Ive moved the code into its own class library and taken all the app settings out and placed them in a database settings table. The only setting ive are in the web config file and is the database connection string, this determines which settings to use. The only issue I can see now is that in my class library i reference xml files to load data. Now depending on if this is web service code or intranet app code will depend if the xml files exist. So should these files also be moved to the class library rather than be in web applicatio
@DarrenMitchinson, I would suggest you put a configuration setting in the web.config of each site with the location of the xml files. Perhaps leave it empty if the files don't exist. Your class library can test this setting to decide what to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.