Spring.Net without configuring it in app.config

无人久伴 提交于 2019-11-28 11:52:02

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6678409/spring-net-without-configuring-it-in-app-config

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!