Application resources, a.k.a. injectables, caching and redis

8 views
Skip to first unread message

Jim Marino

unread,
Oct 16, 2015, 3:09:34 AM10/16/15
to fabric3
Hi,

I've implemented the ability to inject custom resources into components. There were a number of use cases around support for caching and injecting specific types of resources such as Redis clients into components. 

I originally mentioned I wanted to create an @Injectable annotation to support this. However, in looking at it further, I realized the existing @Resource annotation fits this and the custom injectables are "application resources" as opposed to "system resources" (services provided by the runtime).

To use this feature:

1. Create an application resource factory with the DSL in a Provider:

    @Provides
    public static Composite createComposite() {
        QName name = new QName(Namespaces.F3, "ResourceComposite");
        CompositeBuilder builder = CompositeBuilder.newBuilder(name);
        
        // the resource is created using ApplicationResourceBuilder by passing a name and a Supplier and added to the composite
        builder.resource(ApplicationResourceBuilder.newBuilder("AppResource", SomeResourceImpl::new).build()).deployable();
        return builder.build();
    }




2. Inject the resource on a component:


    @Resource(name = "AppResource")
    protected SomeResource resource;



I think this should solve the issue of integrating F3 with caches and other third-party libraries. Let me know how it works.

Jim
 

Tomas Fecko

unread,
Oct 16, 2015, 4:25:15 AM10/16/15
to fab...@googlegroups.com
Hi,

this is looks like a simple solution, reusing the stuff we are already familiar with, I like it.
We will test it...

Tomas

Dňa 16.10.2015 o 9:09 Jim Marino napísal(a):
--
You received this message because you are subscribed to the Google Groups "fabric3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabric3+u...@googlegroups.com.
To post to this group, send email to fab...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fabric3/CA%2B%3DxZJr%3DnOED5iU_D6W4TKBFvfs-WJpaBfSq2xhaa3hbVgt4_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages