Spring.Net without configuring it in app.config

前端 未结 1 1576
孤独总比滥情好
孤独总比滥情好 2020-12-22 08:09

Is there way to configure the objects from inside the code rather than configuring it in xml or app.config file.

相关标签:
1条回答
  • 2020-12-22 08:46

    On the spring.net homepage, you'll find an announcement for the CodeConfig project. CodeConfig allows you to create spring configuration from code, like for instance:

    [Configuration]
    public class MovieFinderConfiguration
    {
    
        [Definition]
        public virtual MovieLister MyMovieLister()
        {
            MovieLister movieLister =  new MovieLister();
            movieLister.MovieFinder = FileBasedMovieFinder();
            return movieLister;
    
        }
    
        [Definition]
        public virtual IMovieFinder FileBasedMovieFinder()
        {
            return new ColonDelimitedMovieFinder(new FileInfo("movies.txt"));
        }
    }
    

    You can use this together with any xml configuration you might already have.

    0 讨论(0)
提交回复
热议问题