Results 1 to 8 of 8

Thread: how to move server CAO configuration outside the app.config

  1. #1
    Join Date
    Dec 2005
    Posts
    10

    Default how to move server CAO configuration outside the app.config

    Hello,

    I would like to know if there is a way to have all the config elements for a remote server in a independent file (myFile.config for exemple) rather than the app.config. I 'm currently working in CAO mode and I can't having the server working when I try to migrate the parameters in a specific file (everything runs when using app.config). It 's seem to me that I 'm constrained to use the ContextRegistry to initialize the remoting server configuration and that it's not possible to use the XmlObjectFactory to load the configuration in this case.



    cylt.

  2. #2
    Join Date
    Sep 2004
    Location
    Belgrade, Serbia
    Posts
    613

    Default

    I'm not sure if I completely understand your question, so I'l cover two possible scenarios.

    If you would like to put a complete set of object definitions (or some of the definitions) in a separate file, that's easy to do. Just create a file that has <objects xmlns="http://www.springframework.net"> element as a root and put your definitions in there.

    All you need to do then is change context definition in your App.config to load definitions from the file resource instead of config element resource:

    Code:
    <context>
        <resource uri="file&#58;//Path/myFile.config"/>
    </context>
    However, if you just want to use property placeholders within your object definitions and then define replacement values outside of your App.config, I don't think you can do it, but I'm not 100% certain. Mark/Rick, you guys are more familiar with the property placeholder functionality, so I will let you answer this.

    Later,

    Aleks

  3. #3
    Join Date
    Dec 2005
    Posts
    10

    Default

    Thank you for your response.

    What i would like to do exactly is having something like this in the initialization part of a server process, for loading a CAO config set of objects :
    Code:
    XmlObjectFactory m_ObjFactory;
    IResource input = new FileSystemResource&#40;"Components.server.config"&#41;;
    m_ObjFactory = new XmlObjectFactory&#40;input&#41;;
    with the config file like this :

    Code:
          <object name="UserManagementControler" singleton="false" type="BLL.Impl.UserManagementControler, BLLImpl"> </object>
    
          <object name="remoteFactory" type="Spring.Remoting.RemoteFactory, Spring.Services"></object>
    
          <object name="publishedRemoteFactory" type="Spring.Remoting.SaoServiceExporter, Spring.Services">
            <property name="Service" ref="remoteFactory"/>
            <property name="ServiceName" value="RemoteFactory"/>
          </object>
    The problem is that it only work if i put the previous config parameters in the app.config and if i use the IApplicationContext ctx = ContextRegistry.GetContext(); for initialization.

    I would like to put all the configuration items out of the app.config

    cylt.

  4. #4
    Join Date
    Oct 2004
    Posts
    9

    Default

    Here a possible solution:
    create a new XmlApplicationContext instead of XmlObjectFactory

    Apart from extended functionalities, XmlApplicationContext will start all your singletons, while with XmlObjectFactory you should call PreInstatiateSingletons to have them created.

    Cheers,
    Federico

  5. #5
    Join Date
    Dec 2005
    Posts
    10

    Default

    Thank you for your response,

    It's work fine with your solution.

    To complete my first question, is there a solution for having all the remoting configuration params hold by the Spring config file : my app.config still have this entries :

    Code:
      <system.runtime.remoting>
        <application>
          <service>
            <activated type="BLL.Impl.UserManagementControler, BLLImpl"/>
          </service>
          <channels>
            <channel ref="tcp" port="9000" />
          </channels>
        </application>
      </system.runtime.remoting>
    and I would like this informations to be wrapped by the Spring config file and been automatically "published".

    cylt.

  6. #6
    Mark Pollack is offline Spring.NET Co-Lead Spring TeamSpring User
    Join Date
    Sep 2004
    Location
    New York, NY
    Posts
    1,683

    Default

    Hi,

    There are no Spring factory objects that will perform, say, programmatic channel registration for you, that will need to be done using the standard .NET remoting configuration. I think you should be fine if you just list the channel information in app.config and remove the following entry:

    Code:
    <service> 
      <activated type="BLL.Impl.UserManagementControler, BLLImpl"/> 
    </service>
    in the standard app.config settings. To obtain a CAO reference to the object UserManagementControler the spring server configuration file you had
    Code:
    <object name="UserManagementControler" singleton="false" type="BLL.Impl.UserManagementControler, BLLImpl"> </object> 
    
    <object name="remoteFactory" type="Spring.Remoting.RemoteFactory, Spring.Services"></object> 
    
    <object name="publishedRemoteFactory" type="Spring.Remoting.SaoServiceExporter, Spring.Services"> 
      <property name="Service" ref="remoteFactory"/> 
      <property name="ServiceName" value="RemoteFactory"/> 
    </object>
    looks fine. Just have your server app.config contain only the following channel registration information, i.e.
    Code:
       <system.runtime.remoting> 
        <application> 
          <channels> 
            <channel ref="tcp" port="9000" /> 
          </channels> 
        </application> 
      </system.runtime.remoting>
    Take a look at the sample Remoting application and how the instance of "prototypeCalculator" is obtained on the client and the corresponding server side configuration.

    If you would like to remove the need to use the standard .NET channel configuration, there are a few options, we can create a ChannelFactoryObject that will perform the appropriate programmatic registration or even use the custom XML schema support to mimic the .NET App.config syntax exactly. (That would be the cool way to do it!)

    It is a bit of busy work, since there are a fair amount of properties to support it fully. Alternatively, you can write a minimal ChannelFactoryObject, or a small helper class, or code inside an 'init method' that will call
    Code:
    TcpChannel channel = new TcpChannel&#40;9000&#41;;
    ChannelServices.RegisterChannel&#40;channel&#41;;
    This would let you use things like propery placeholders to set the tcp port number - which might the whole point of why you want to shift this configuration into spring and not the standard .net app.config section.

    Let me know if I can help out more - I can code up the ChannelFactoryObject if you think it will be helpful.

    Cheers,
    Mark

  7. #7
    Join Date
    Sep 2004
    Location
    Leeds, UK
    Posts
    166

    Default

    Hiya

    The MethodInvokingFactoryObject can also be used to achieve what you want; it is, however, verbose in the extreme :?

    Code:
    <object type="Spring.Objects.Factory.Config.MethodInvokingFactoryObject">
    	<property name="targetType"
                 value="System.Runtime.Remoting.Channels.ChannelServices, mscorlib"/>
    	<property name="targetMethod" value="RegisterChannel"/>
    	<property name="arguments">
    		<list>
    			<object type="System.Runtime.Remoting.Channels.Tcp.TcpChannel, System.Runtime.Remoting">
    				<constructor-arg name="port" value="8005"/>
    			</object>
    		</list>
    	</property>
    </object>
    Mark's suggestion of keeping the channel configuration in the xxx.config file is the way to go... I'm not sure how much would be gained by creating a custom IFactoryObject implementation. There are also issues relating to initialization order (other objects will have to express a dependency via the 'depends-on' attribute), using it outside an IApplicationContext, etc.

    Cheers
    Rick
    Senior Consultant, Interface21 - Spring Services from the Source

    The Spring Experience - The Premier Spring Event of 2006. December 7-10, 2006, Hollywood, Florida

  8. #8
    Join Date
    Dec 2005
    Posts
    10

    Default

    Mark, Rick,

    Thank you for your good advices.
    I think there is no needs to code a ChannelFactoryObject, my question was purely informative to know if there was a more "elegant" way to build this part of my application. For some deployment 's problematics I think it 's interesting to have a separation between the general's application configuration properties and the business component's one's. That's the reason why I'm trying to shift the remoting configuration of my business components out of the app.config.

    cylt.
    [/url]

Similar Threads

  1. Validating the whole xml configuration
    By Thibaut in forum Core Container
    Replies: 1
    Last Post: 09-21-2005, 06:46 PM
  2. Replies: 5
    Last Post: 08-13-2005, 01:17 PM
  3. Replies: 2
    Last Post: 07-21-2005, 07:53 PM
  4. Replies: 2
    Last Post: 04-22-2005, 10:08 PM
  5. Configuration File Strategy
    By Tom Whitner in forum Core Container
    Replies: 5
    Last Post: 11-23-2004, 07:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •