Search code examples
dotnetnuke2sxc

2sxc - Use shared classes in SxcApiController


If I use that code for my ScxApiController

public class InstallController : SxcApiController
{
    [HttpGet]
    [AllowAnonymous]
    public object Test()
    {
        return new MyObj();
    }
}

public class MyObj
{
    public int MyProperty1 { get; set; }
    public int MyProperty2 { get; set; }
    public int MyProperty3 { get; set; }
}

All work fine, but I want to be able to put MyObj code to separete file. If I just move this code to separate file the class is not found. How I can move this code outside the main class that still work?

==== Solution 1 ==========================================

1 - Move MyObj file to /App_Code folder

2 - Add namespace in this new file

3 - Use MyObj with namespace or add using

This is OK for custom project but don't know how to pack this file to module installer


Solution

  • Basically what you want to do is beyond the standard compile-on-demand setup. Usually you would put this in a visual studio project and build DLLs. This is of course more complex than what 2sxc is usually used for, but we also do this a lot when we have sophisticated business logic.