
{"id":307,"date":"2009-10-16T23:41:29","date_gmt":"2009-10-17T03:41:29","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=307"},"modified":"2009-10-16T23:41:29","modified_gmt":"2009-10-17T03:41:29","slug":"wcf-configuration-thou-shalt-not-hard-code","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=307","title":{"rendered":"WCF Configuration: Thou Shalt Not Hard Code"},"content":{"rendered":"<p>WCF comes with a very handy configuration language that allows you to define bindings, end point properties and the like. Doing the same in code is a) tedious, b) inflexible: any minuscule change would require recompilation and redeployment.<\/p>\n<p>The trouble is, the configuration information is read from the .NET configuration file, which is unconditionally set to <code><i>calling_executable<\/i>.exe.config<\/code>, at least for the primary app domain. This is true even if the calling executable is not a .NET application.<\/p>\n<p>This inflexible rule stands in a way of self-contained libraries that use WCF. It is not possible to define WCF configuration on a per library basis, it must be done at the application level. Not only we have a leaking abstraction here, this abstraction may leak into very interesting places. E.g. if you are writing a COM+ component, the configuration file it will use suddenly depends on whether it is in-proc or out-of-proc, and all out-of-proc components may as well end up reading <code>dllhost.exe.config<\/code>.<\/p>\n<p>Modular application that load plugins dynamically (along the lines of CAB) face even bigger problem. It is not possible to know in advance what WCF settings will be used by a plug-in, so this information cannot be placed into the application config.<\/p>\n<p>Reading a different configuration file should have been easy, but it is not. WCF is really hardwired to <code><i>calling_exe<\/i>.exe.config<\/code>. Some redirection is possible, but it is quite verbose and complicated (see &#8220;<a href=\"http:\/\/weblogs.asp.net\/cibrax\/archive\/2007\/10\/19\/loading-the-wcf-configuration-from-different-files-on-the-client-side.aspx\">Loading the WCF configuration from different files on the client side<\/a>&#8220;).<\/p>\n<p>This is only one consequence of Microsoft&#8217;s decision to hardwire the configuration to a specific file. In the Java world this decision would probably be unthinkable. Almost everything in Java can be substituted to a different implementation. If it&#8217;s not an interface, it&#8217;s a system property. .NET, however, pursues a different philosophy (see &#8220;<a href=\"http:\/\/www.ikriv.com\/en\/prog\/info\/dotnet\/JavaClone\/index.html\">Is .NET Really a Java Clone?<\/a>&#8220;).<\/p>\n<p>In many cases it is fine, but the decision to hardwire the configuration path is unfortunate and it keeps biting us. Mr. Gates, thou shalt not hard code!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WCF comes with a very handy configuration language that allows you to define bindings, end point properties and the like. Doing the same in code is a) tedious, b) inflexible: <a href=\"https:\/\/ikriv.com\/blog\/?p=307\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[3,4],"tags":[],"class_list":["entry","author-ikriv","post-307","post","type-post","status-publish","format-standard","category-dotnet","category-hack"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=307"}],"version-history":[{"count":0,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}