diff --git a/pom.xml b/pom.xml
index 700ba48..4fea2a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,6 +86,44 @@
provided
+
+
+
+ org.apache.geronimo.specs
+ geronimo-jcdi_2.0_spec
+ 1.0.1
+ test
+
+
+
+ javax.interceptor
+ javax.interceptor-api
+ 1.2.1
+ test
+
+
+
+ javax.enterprise
+ cdi-api
+ ${cdi}
+ provided
+ true
+
+
+
+ javax.annotation
+ javax.annotation-api
+ ${javax-annotation-api}
+ test
+
+
+
+ org.apache.openwebbeans
+ openwebbeans-se
+ ${webbeans}
+ test
+
+
diff --git a/src/main/asciidoc/new-features.adoc b/src/main/asciidoc/new-features.adoc
index 0221325..817f8e8 100644
--- a/src/main/asciidoc/new-features.adoc
+++ b/src/main/asciidoc/new-features.adoc
@@ -1,6 +1,10 @@
[[new-features]]
= New & Noteworthy
+[[new-features.2.1]]
+== What's new in Spring Data LDAP 2.1
+* CDI extension to create LDAP repositories within a CDI container.
+
[[new-features.2.0]]
== What's new in Spring Data LDAP 2.0
* Enhanced tooling support by using Spring Framework's `@NonNullApi` and `@Nullable` annotations.
diff --git a/src/main/asciidoc/reference/ldap-repositories.adoc b/src/main/asciidoc/reference/ldap-repositories.adoc
index 17a667b..8e63a6b 100644
--- a/src/main/asciidoc/reference/ldap-repositories.adoc
+++ b/src/main/asciidoc/reference/ldap-repositories.adoc
@@ -229,3 +229,39 @@ Basic QueryDSL support is included in Spring LDAP. This support includes the fol
* A Query implementation, `QueryDslLdapQuery`, for building and executing QueryDSL queries in code.
* Spring Data repository support for QueryDSL predicates. `QueryDslPredicateExecutor` includes a number of additional methods with appropriate parameters; extend this interface along with `LdapRepository` to include this support in your repository.
+[[ldap.repositories.misc]]
+== Miscellaneous
+
+[[ldap.repositories.misc.cdi-integration]]
+=== CDI Integration
+
+Instances of the repository interfaces are usually created by a container, which Spring is the most natural choice when working with Spring Data. As of version 2.1 Spring Data LDAP ships with a custom CDI extension that allows using the repository abstraction in CDI environments. The extension is part of the JAR so all you need to do to activate it is dropping the Spring Data LDAP JAR into your classpath. You can now set up the infrastructure by implementing a CDI Producer for the `LdapTemplate`:
+
+[source,java]
+----
+class LdapTemplateProducer {
+
+ @Produces
+ @ApplicationScoped
+ public LdapOperations createLdapTemplate() {
+
+ ContextSource contextSource = …
+ return new LdapTemplate(contextSource);
+ }
+}
+----
+
+The Spring Data LDAP CDI extension will pick up the `LdapTemplate` available as CDI bean and create a proxy for a Spring Data repository whenever a bean of a repository type is requested by the container. Thus obtaining an instance of a Spring Data repository is a matter of declaring an `@Inject`-ed property:
+
+[source,java]
+----
+class RepositoryClient {
+
+ @Inject
+ PersonRepository repository;
+
+ public void businessMethod() {
+ List people = repository.findAll();
+ }
+}
+----
diff --git a/src/main/java/org/springframework/data/ldap/repository/cdi/LdapRepositoryBean.java b/src/main/java/org/springframework/data/ldap/repository/cdi/LdapRepositoryBean.java
new file mode 100644
index 0000000..6c5f29f
--- /dev/null
+++ b/src/main/java/org/springframework/data/ldap/repository/cdi/LdapRepositoryBean.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.ldap.repository.cdi;
+
+import java.lang.annotation.Annotation;
+import java.util.Optional;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.springframework.data.ldap.repository.support.LdapRepositoryFactory;
+import org.springframework.data.repository.cdi.CdiRepositoryBean;
+import org.springframework.data.repository.config.CustomRepositoryImplementationDetector;
+import org.springframework.ldap.core.LdapOperations;
+import org.springframework.util.Assert;
+
+/**
+ * {@link CdiRepositoryBean} to create LDAP repository instances.
+ *
+ * @author Mark Paluch
+ * @since 2.1
+ */
+public class LdapRepositoryBean extends CdiRepositoryBean {
+
+ private final Bean operations;
+
+ /**
+ * Creates a new {@link LdapRepositoryBean}.
+ *
+ * @param operations must not be {@literal null}.
+ * @param qualifiers must not be {@literal null}.
+ * @param repositoryType must not be {@literal null}.
+ * @param beanManager must not be {@literal null}.
+ * @param detector detector for the custom {@link org.springframework.data.repository.Repository} implementations
+ * {@link CustomRepositoryImplementationDetector}, can be {@link Optional#empty()}.
+ */
+ LdapRepositoryBean(Bean operations, Set qualifiers, Class repositoryType,
+ BeanManager beanManager, Optional detector) {
+
+ super(qualifiers, repositoryType, beanManager, detector);
+
+ Assert.notNull(operations, "LdapOperations bean must not be null!");
+ this.operations = operations;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class)
+ */
+ @Override
+ protected T create(CreationalContext creationalContext, Class repositoryType,
+ Optional