Start a new topic
Answered

Execute code on the fly (Startup logic)

I am working on a DuoCode binding for one of my Javascript libraries found here


https://github.com/AndersMalmgren/Knockout.BindingConventions


I want to override a reference called ko.bindingConventions.viewLocator with duocode logic. Doing it from a static constructor wont work because the binding logic does not have a entry point in the form of a duocode class that I can have a static constructor for. The entry point is my javascript library. Is there a assembly level attribute I can use? Like the OwinStartup attribute? 


http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection


Best Answer

This feature was implemented in DuoCode 1.4 that will be available in the coming week.


Usage:

[assembly: CompilerOptions(Startup = typeof(Some_Startup_Class))]`

```/// <summary>
/// Static constructor of specified class will be called on script (assembly) load.
/// </summary>
public Type Startup { get; set; }

Any thoughts on this? I would say its a very important feature for Libraries like my library here 


https://github.com/AndersMalmgren/Knockout.BindingConventions.DuoCode/blob/master/Knockout.BindingConventions.DuoCode/Binding.cs#L13


I dont want to force my users to explicitly call Binding.Init() but rather it executes it self. Something like


[assembly: Startup(typeof(Binding))]


Then your compiler can look for a static method Init or something that can be called on the fly 

Hi, I have been away for a while. Any thoughts on this feature? Its a very important feature for DuoCode libraries that need to inject at runtime into existing javascript code

Thanks it's very good idea.

We will try to add it soon, by calling static .cctor of the class provided.


As a workaround currently you can use some static Program.Main() method with [Js.InvokeMainMode(InvokeMainMode.Immediate)] attribute, but this requires compile your assembly as "exe" and not as "class library/dll".


Thanks

Answer

This feature was implemented in DuoCode 1.4 that will be available in the coming week.


Usage:

[assembly: CompilerOptions(Startup = typeof(Some_Startup_Class))]`

```/// <summary>
/// Static constructor of specified class will be called on script (assembly) load.
/// </summary>
public Type Startup { get; set; }
Login or Signup to post a comment