开发者

Retrieve config file path an object is configured in in Spring.NET

I'd like to configure an object in Spring.NET that is able to read additional configuration files. Those files should be located relative to the Spring.NET configuration file (or app.config if Spring.NET config lays there).

So what I need is a way to find out from which config file the object definition for my object comes from. Or if there is no config file (since it has been configured programmatically).

If there is no generic solution to this (I'm afraid there isn't one...) a solution that is specifically for XmlApplicationContext would also do.

What I tried until now was deriving from IApplicationContextAware and then casting the app context to XmlApplicationContext. 开发者_JAVA百科This contains the property ConfigurationLocations. But this does not work since ConfigurationLocations

  • is protected so not accessible
  • is an array of files so if there is more than one file I don't know from which one my object comes
  • specific to XmlApplicationContext (as said: ok but not optimal)
  • I'm sure this won't work if config is inside app.config.

Is there any solution to my problem?


I can confirm that there is no way to correlate the ObjectDefinition of a specific object defined for the Context with the specific 'source' of that ObjectDefinition once its been registered.

The design of the underlying ObjectFactory for the Context is specifically such that its doesn't needs to know/care where the ObjectDefinition metadata originated but to merge all the metadata together when initializing the ObjectFactory.

I'd watch out about "keeping track" of the path to the config files anyway b/c while this may work for your specific use-case, its unlikely to be a good general-purpose solution to the problem b/c an important tenet of the Spring.NET config file design is that one config file can 'import' one or more other config files which in turn can import one or more others, etc. and so knowing the full path to just one of these inter-dependent config files won't (necessarily) have anything to do with the path to the actual config file that contains the metadata for the specific object you are seeking.

Again, if you are in complete control of the format/content of the config files, then your work-around might be viable, but just be aware that its probably not a good general-purpose solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜