You don't need to use in Sitecore 9 the LeaseOwner and lock/unlock contacts.
With Sitecore xConnect it was simplified a lot how to send data to xDB.
In Sitecore 8+ to update data you have to use next code:
public void SetContactData(string username)
{
LeaseOwner leaseOwner = new LeaseOwner("YOUR_WORKER_NAME", LeaseOwnerType.OutOfRequestWorker);
ContactRepositoryBase contactRepository = Factory.CreateObject("contactRepository", true) as ContactRepositoryBase;
// Attempt to obtain an exclusive lock on an existing contact in xDB.
LockAttemptResult<Contact> lockResult = contactRepository.TryLoadContact(username, leaseOwner,
TimeSpan.FromMinutes(1));
Contact contact = null;
if (lockResult.Status == LockAttemptStatus.AlreadyLocked)
{
// Another worker or a live web session has an exclusive lock on the contact.
// You can't use this contact right now. It's up to you what to do in this case.
/* ... */
}
else if (lockResult.Status == LockAttemptStatus.DatabaseUnavailable)
{
// Database is down. Try to handle this gracefully.
/* ... */
}
else if (lockResult.Status == LockAttemptStatus.NotFound)
{
// A contact with the given identifier doesn't exist.
// Just create a new contact object.
contact = contactRepository.CreateContact(Guid.NewGuid());
// Identify it.
contact.Identifiers.Identifier = username;
// And make it known.
contact.Identifiers.IdentificationLevel = Sitecore.Analytics.Model.ContactIdentificationLevel.Known;
}
else
{
// We successfull locked an existing contact.
contact = lockResult.Object;
}
// Set some contact facets:
/* ... */
// Save the contact and release the lock.
if (contact != null)
{
var options = new ContactSaveOptions(release: true, owner: leaseOwner);
contactRepository.SaveContact(contact, options);
}
}
with Sitecore 9 is pretty simple :
public void UpdateContact(string source, string identifier, Data data)
{
using (XConnectClient client = GetClient())
{
IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier);
Contact contact = client.Get<Contact>(reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey));
if (contact == null)
{
return;
}
// Set Facets
client.SetFacet<PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInformation);
client.Submit();
}
}