I have a custom workflow, which requires a set of external dependencies. and i am having trouble injecting them.
I tried to update the constructor but that leads to a boot error and i can't get past it. Also tried to property inject (i know not ideal) but my properties are always null.
Is there way to do this via a constructor? if not, how do i get property injection to work with the Umbraco DI wrapper around LightInject which seems to do it out of the box?
Essentially what you need to do is create a component to register your dependencies (or any other code that needs to run on startup), then register that component in a collection, which is implemented by a composer. Probably over-simplifying the explanation, but that's the guts of it.
Key part from the docs:
namespace My.Website
{
public class SubscribeToContentServiceSavingComposer : IUserComposer
{
public void Compose(Composition composition) {
Composition.Components().Append<SubscribeToContentServiceSavingComponent>();
}
}
public class SubscribeToContentServiceSavingComponent : IComponent
{
// initialize: runs once when Umbraco starts
public void Initialize()
{
ContentService.Saving += ContentService_Saving;
}
// terminate: runs once when Umbraco stops
public void Terminate()
{
}
private void ContentService_Saving(IContentService sender, ContentSavingEventArgs e)
{
// do something when content saves
}
}
}
Does something like this work with a Umbraco Forms workflow as that is what i am dealing with, if so does anyone know where i could find any examples to take a look at as well as the docs?
Also, i have a bunch of dependencies, would i have to create a component for each one, i was hoping this was simple case of me not getting the Umbraco composer wrapper around light inject which has property injection out of the box.
Not sure about Forms sorry... Not being OSS, Forms can be tricky to work with since there's no repo to poke through...
Re multiple dependencies, these can be registered in a single component, or you could create multiple components to logically group the dependencies. As far as I know, either option is fine.
I am not sure a component would work here. I mean the underlying theory works but there doesn't seem to be a function to hook into, the RecordService no longer seems to exist from samples i have found.
I am trying to hijack the On Approve event of the form, so when a record is approved some other processing works.
The custom workflow works, but i have to hard code all dependencies and i also need the UmbracoHelper so i used the IUmbracoContextFactory in the dependendency that needed it, but it becomes pretty useless if i can't inject.
LightInject states it has this out of the box (property injection) not sure why the Umbraco wrapper cripples this or its not well documented.
Did you find a way to inject into a workflow? I'm facing the same issue and at the moment I'm having to use the AutoFac dependency resolver to get the service which isn't ideal.
WorkflowType Dependency Injection (DI)
Hi all,
I have a custom workflow, which requires a set of external dependencies. and i am having trouble injecting them.
I tried to update the constructor but that leads to a boot error and i can't get past it. Also tried to property inject (i know not ideal) but my properties are always null.
Is there way to do this via a constructor? if not, how do i get property injection to work with the Umbraco DI wrapper around LightInject which seems to do it out of the box?
Thanks,
Rob
Hi Rob
Have you looked at the Composer/Component pattern? There's a solid set of docs at https://our.umbraco.com/documentation/Implementation/Composing/
Essentially what you need to do is create a component to register your dependencies (or any other code that needs to run on startup), then register that component in a collection, which is implemented by a composer. Probably over-simplifying the explanation, but that's the guts of it.
Key part from the docs:
Hi Nathan,
Does something like this work with a Umbraco Forms workflow as that is what i am dealing with, if so does anyone know where i could find any examples to take a look at as well as the docs?
Also, i have a bunch of dependencies, would i have to create a component for each one, i was hoping this was simple case of me not getting the Umbraco composer wrapper around light inject which has property injection out of the box.
Not sure about Forms sorry... Not being OSS, Forms can be tricky to work with since there's no repo to poke through...
Re multiple dependencies, these can be registered in a single component, or you could create multiple components to logically group the dependencies. As far as I know, either option is fine.
I am not sure a component would work here. I mean the underlying theory works but there doesn't seem to be a function to hook into, the RecordService no longer seems to exist from samples i have found.
I am trying to hijack the
On Approve
event of the form, so when a record is approved some other processing works.The custom workflow works, but i have to hard code all dependencies and i also need the
UmbracoHelper
so i used theIUmbracoContextFactory
in the dependendency that needed it, but it becomes pretty useless if i can't inject.LightInject states it has this out of the box (property injection) not sure why the Umbraco wrapper cripples this or its not well documented.
Any help would be greatly appreciated.
Did you find a way to inject into a workflow? I'm facing the same issue and at the moment I'm having to use the AutoFac dependency resolver to get the service which isn't ideal.
is working on a reply...