This project is read-only.

Passing server objects into spark template

Topics: faq
Jul 29, 2011 at 10:31 PM

This is probably a stupid question, so I apologize in advance!

I am using the C# webserver platform along with the spark MVC library. I have a c# object called "host" that is available to me when I set up the web server, but now what I want to do is to be able to reference the data contained in host. Host is a singleton object, so it's data will be persistent for the life of the server, but I just can't figure out how to make my spark pages "see" it.

Here is some code:

public createServer(MonitorHost host)
    var filter = new LogFilter();

    Assembly thisAssembly = typeof(Program).Assembly;

    // create a MVC web server.
    var server = new MvcServer();
    server.ViewEngines.Add(new SparkEngine());

    // use one http listener.
    server.Add(HttpListener.Create(IPAddress.Any, 8550));
    var module = new FileModule();
    module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\Content\\"));
    // Load controllers and embedded views.
    BootStrapper bootStrapper = new BootStrapper(server);

    // start server, can have max 5 pending accepts.

Everything works as expected with the resulting spark template, except I REALLY want to be have visibility into the host object (passed through to the function above) and its data and members in my spark controller. And based on the documentation for C# webserver and Spark MVC, I can't figure out how to do that. Any ideas?



Aug 2, 2011 at 6:19 PM

Hi, any ideas on this post? Basically, what I'm trying to do is something similar to what you might find from an embedded webserver to configure a router or something. The reason I want to pass my host object to the webserver is so I can use my server pages to configure its values while it is in memory. This seems like it must be a fairly common use for an embedded web server, but I can't figure out how to support it with this architecture.

Basically, I just want to use a C# object reference instead of, say, a database as my data source, but I can't figure out how to pass my reference in a manner that will be accessible by the web server template pages.