Spring.Net without configuring it in app.config

2020-02-15 23:17发布

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

标签: spring.net
1条回答
萌系小妹纸
2楼-- · 2020-02-15 23:56

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.

查看更多
登录 后发表回答