Created
December 13, 2018 15:29
-
-
Save odinserj/855f72b726f7fdb0f718c3ab07ba3a82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyAutofacActivator : JobActivator | |
{ | |
private readonly ILifetimeScope _lifetimeScope; | |
public MyAutofacActivator(ILifetimeScope lifetimeScope) | |
{ | |
_lifetimeScope = lifetimeScope; | |
} | |
public override JobActivatorScope BeginScope(JobActivatorContext context) | |
{ | |
var connection = context.GetJobParameter<string>("Connection"); | |
return new AutofacScope(_lifetimeScope.BeginLifetimeScope(config => | |
{ | |
config.Register(x => new SqlConnection(connection)).As<SqlConnection>(); | |
})); | |
} | |
class AutofacScope : JobActivatorScope | |
{ | |
private readonly ILifetimeScope _lifetimeScope; | |
public AutofacScope(ILifetimeScope lifetimeScope) | |
{ | |
_lifetimeScope = lifetimeScope; | |
} | |
public override object Resolve(Type type) | |
{ | |
return _lifetimeScope.Resolve(type); | |
} | |
public override void DisposeScope() | |
{ | |
_lifetimeScope.Dispose(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment