-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order of Execution of Startup Codes located on Different Assemblies #10
Comments
The slightly strange part is that when dealing with unrelated assemblies, the Order attribute is not necessarily meaningful across assemblies (though I know in your case it is). Still, I guess it's probably harmless, as long as the ordering within one assembly is honored. Feel free to send a PR if you have a clean change to do this. Make sure it is efficient in scenarios where there could be a lot of assemblies in bin. Thanks! |
I've encountered this as well when using RazorGenerator. Each RazorGenerator project has it's own RazorGeneratorMvcStart.cs file in the App_Start folder so that it can register its view engine in the list. I need to be able to specify the order of these so that the main project happens first, followed by each engine as needed. Sort of a reverse dependency ordering. If this doesn't happen, I wind up with view hiding because the ViewEngines are looking things up in the wrong order. |
I see. So it sounds like you would want something where you can specify the order in which WebActivator processes entire assembly, and not so much control it globally at the level of each Question: do the assemblies that you want to order have dependencies on each other? If so, we could conceivably walk the dependency graph to automatically order them with children before parents. |
I think that having WebActivator walk the dependency graph would work in most cases. Under normal circumstances I would expect the assemblies higher up the chain should initialize first. However in this circumstance I want them to run in reverse order, with my project firing first, then having sub-assemblies firing afterward. The reason is that RazorGenerator adds ViewEngines to the list (which is being treated like a stack). If my project registers it's view engine last then it winds up on top of the stack and ends up hiding views from other engines lower in the stack. |
While we're talking dependency graphs, would it be an idea in that case to allow users to specify dependencies explicitly on a type basis like so? [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(App.App_Start.MyStart), "PreStart",
RunBefore = typeof(ExternalAssembly.App_Start.OtherStart)
)] Of course this requires referencing the other assembly which might be difficult and introduce circular references. So it would be better to specify dependecies by type name as a string instead. It might certainly be overkill for most situations but it would probably make it safer to order start methods from different sources where you don't know what other packages may be included and how these are specified. |
Note that there is a pending pull request #13 that could allow this is a different way, by making the Order attribute work across all assemblies. It's not as 'clean' as creating a dependency graph by pointing to types, but it has simplicity going for it. Do you think that would achieve your needs? |
Yes. We have setup our own dependency system, but it is made unreliable by On Tue, Jul 30, 2013 at 12:54 AM, David Ebbo [email protected]:
|
Yes, we should probably get this change in. |
Great, since I control all assemblies that need to be ordered, simply ordering by the attribute value is definitely sufficient. |
Ok, that change is now in WebActivatorEx 2.0.3. Could you please give it a try to make sure it works well for everyone? Thanks! |
What would happen if, for instance, the order for two assemblies is similar? (both assemblies with order=2) Will this throw an error or resort to some kind of a default ordering scheme? |
@TheFurryMonk note that the Order is applied to each PreStart attribute, and not at the assembly level. But in any event, if multiple PreStart have the same Order, it is not an error, but the order between them is arbitrary. |
Okay so let me describe what I'm doing. I have a solution with multiple projects. Let's say I have the projects: Project1 (which is the startup project), Project2, and so on. On some of these projects I have a folder: App_Start where my desired startup codes are located. On the webactivator attribute I specify the desired "Order" for the execution on each code.
The issue is that the sequence of the execution (on multiple assemblies) isn't exactly followed because as soon as an attribute on an assembly is found, the corresponding code is then executed. For example: if Project1 assembly is found first... it will start running the code... even if the Order = 2 (just an example).... but not the code with Order = 1 because it is on another assembly.
I ended up writing my own activator where I scan all assemblies first for any of the startup attributes, put the result on a list, sorting them based on the order, ... then executing the codes.
Is there a chance for webactivator to behave like this? I can place all startup codes in one place and everything would be good... but for some reasons I just like placing each startup code on different assemblies (where they are related... example I place my DI registration startup code on the project that is about DependencyResolution.)
The text was updated successfully, but these errors were encountered: