What is it meant by local vs global objects in this article about dependency injection?
up vote
1
down vote
favorite
What do the words local
and global
mean in this article about dependency injection ?
Please see the quote below :
Data objects, on the other hand, are created dynamically, either in
response to user interaction, API invocation, scheduled tasks, etc.
They usually have a short, local lifespan. They carry and
manipulate the data that the application processes. They might combine
data and behavior, or be pure, “thin”, data structures.
The crucial property of the service/module graph is that it is created
statically. Only when the graph of services is wired, the application
is usually ready to serve user requests. Hence the service
objects/modules are static and global, as well as typically
stateless.
dependency-injection global local
add a comment |
up vote
1
down vote
favorite
What do the words local
and global
mean in this article about dependency injection ?
Please see the quote below :
Data objects, on the other hand, are created dynamically, either in
response to user interaction, API invocation, scheduled tasks, etc.
They usually have a short, local lifespan. They carry and
manipulate the data that the application processes. They might combine
data and behavior, or be pure, “thin”, data structures.
The crucial property of the service/module graph is that it is created
statically. Only when the graph of services is wired, the application
is usually ready to serve user requests. Hence the service
objects/modules are static and global, as well as typically
stateless.
dependency-injection global local
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
What do the words local
and global
mean in this article about dependency injection ?
Please see the quote below :
Data objects, on the other hand, are created dynamically, either in
response to user interaction, API invocation, scheduled tasks, etc.
They usually have a short, local lifespan. They carry and
manipulate the data that the application processes. They might combine
data and behavior, or be pure, “thin”, data structures.
The crucial property of the service/module graph is that it is created
statically. Only when the graph of services is wired, the application
is usually ready to serve user requests. Hence the service
objects/modules are static and global, as well as typically
stateless.
dependency-injection global local
What do the words local
and global
mean in this article about dependency injection ?
Please see the quote below :
Data objects, on the other hand, are created dynamically, either in
response to user interaction, API invocation, scheduled tasks, etc.
They usually have a short, local lifespan. They carry and
manipulate the data that the application processes. They might combine
data and behavior, or be pure, “thin”, data structures.
The crucial property of the service/module graph is that it is created
statically. Only when the graph of services is wired, the application
is usually ready to serve user requests. Hence the service
objects/modules are static and global, as well as typically
stateless.
dependency-injection global local
dependency-injection global local
edited Nov 10 at 13:09
lagom
3,41661737
3,41661737
asked Nov 9 at 19:15
jhegedus
8,985753115
8,985753115
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
The author is differentiating the service objects that compose an application vs the data objects used in an application. Services are global since they are commonly accessible (via injection) to the entire application. An object graph of such services are created when bootstrapping your application with DI. After this object graph is created, your application will use these same services throughout the application for the entire life of your application.
Data objects, on the other hand, have a local scope. They are created dynamically as needed, used, and then disposed.
For instance, supposed you have a UserRepositoryService and you want to register a new User. The UserRepsitoryService is configured and injected throughout your application (and thus global), but the User object is created dynamically in response to the request to create a new User. After the operation is complete, the User object can fall out of scope and be disposed.
public class Application {
private IRepository<User> _userRepo = null;
// UserRepositoryService injected through DI here
public Application(IRespository<User> userRepo) { _userRepo = userRepo; }
...
public void CreateUser(String userId) {
User newUser = new User(userId); // Data Object Created
_userRepo.Insert(newUser);
} // Data Object falls out of scope here
}
This is a simple example, but hope that helps.
Thanks for the answer still trying to wrap my head around DI so maybe first I need to understand some even more basic concepts before I try to understand the answer to this question. ( I came to the conclusion that this is on the "next level". I am missing the basics. )
– jhegedus
Nov 19 at 5:14
1
@jhegedus The best remedy for that is to go through some example DI applications and get some experience writing your own. I think it takes everyone a while to grasp ioc, since it flips everything on its head.
– Ryan Pierce Williams
Nov 19 at 20:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232000%2fwhat-is-it-meant-by-local-vs-global-objects-in-this-article-about-dependency-inj%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The author is differentiating the service objects that compose an application vs the data objects used in an application. Services are global since they are commonly accessible (via injection) to the entire application. An object graph of such services are created when bootstrapping your application with DI. After this object graph is created, your application will use these same services throughout the application for the entire life of your application.
Data objects, on the other hand, have a local scope. They are created dynamically as needed, used, and then disposed.
For instance, supposed you have a UserRepositoryService and you want to register a new User. The UserRepsitoryService is configured and injected throughout your application (and thus global), but the User object is created dynamically in response to the request to create a new User. After the operation is complete, the User object can fall out of scope and be disposed.
public class Application {
private IRepository<User> _userRepo = null;
// UserRepositoryService injected through DI here
public Application(IRespository<User> userRepo) { _userRepo = userRepo; }
...
public void CreateUser(String userId) {
User newUser = new User(userId); // Data Object Created
_userRepo.Insert(newUser);
} // Data Object falls out of scope here
}
This is a simple example, but hope that helps.
Thanks for the answer still trying to wrap my head around DI so maybe first I need to understand some even more basic concepts before I try to understand the answer to this question. ( I came to the conclusion that this is on the "next level". I am missing the basics. )
– jhegedus
Nov 19 at 5:14
1
@jhegedus The best remedy for that is to go through some example DI applications and get some experience writing your own. I think it takes everyone a while to grasp ioc, since it flips everything on its head.
– Ryan Pierce Williams
Nov 19 at 20:04
add a comment |
up vote
2
down vote
The author is differentiating the service objects that compose an application vs the data objects used in an application. Services are global since they are commonly accessible (via injection) to the entire application. An object graph of such services are created when bootstrapping your application with DI. After this object graph is created, your application will use these same services throughout the application for the entire life of your application.
Data objects, on the other hand, have a local scope. They are created dynamically as needed, used, and then disposed.
For instance, supposed you have a UserRepositoryService and you want to register a new User. The UserRepsitoryService is configured and injected throughout your application (and thus global), but the User object is created dynamically in response to the request to create a new User. After the operation is complete, the User object can fall out of scope and be disposed.
public class Application {
private IRepository<User> _userRepo = null;
// UserRepositoryService injected through DI here
public Application(IRespository<User> userRepo) { _userRepo = userRepo; }
...
public void CreateUser(String userId) {
User newUser = new User(userId); // Data Object Created
_userRepo.Insert(newUser);
} // Data Object falls out of scope here
}
This is a simple example, but hope that helps.
Thanks for the answer still trying to wrap my head around DI so maybe first I need to understand some even more basic concepts before I try to understand the answer to this question. ( I came to the conclusion that this is on the "next level". I am missing the basics. )
– jhegedus
Nov 19 at 5:14
1
@jhegedus The best remedy for that is to go through some example DI applications and get some experience writing your own. I think it takes everyone a while to grasp ioc, since it flips everything on its head.
– Ryan Pierce Williams
Nov 19 at 20:04
add a comment |
up vote
2
down vote
up vote
2
down vote
The author is differentiating the service objects that compose an application vs the data objects used in an application. Services are global since they are commonly accessible (via injection) to the entire application. An object graph of such services are created when bootstrapping your application with DI. After this object graph is created, your application will use these same services throughout the application for the entire life of your application.
Data objects, on the other hand, have a local scope. They are created dynamically as needed, used, and then disposed.
For instance, supposed you have a UserRepositoryService and you want to register a new User. The UserRepsitoryService is configured and injected throughout your application (and thus global), but the User object is created dynamically in response to the request to create a new User. After the operation is complete, the User object can fall out of scope and be disposed.
public class Application {
private IRepository<User> _userRepo = null;
// UserRepositoryService injected through DI here
public Application(IRespository<User> userRepo) { _userRepo = userRepo; }
...
public void CreateUser(String userId) {
User newUser = new User(userId); // Data Object Created
_userRepo.Insert(newUser);
} // Data Object falls out of scope here
}
This is a simple example, but hope that helps.
The author is differentiating the service objects that compose an application vs the data objects used in an application. Services are global since they are commonly accessible (via injection) to the entire application. An object graph of such services are created when bootstrapping your application with DI. After this object graph is created, your application will use these same services throughout the application for the entire life of your application.
Data objects, on the other hand, have a local scope. They are created dynamically as needed, used, and then disposed.
For instance, supposed you have a UserRepositoryService and you want to register a new User. The UserRepsitoryService is configured and injected throughout your application (and thus global), but the User object is created dynamically in response to the request to create a new User. After the operation is complete, the User object can fall out of scope and be disposed.
public class Application {
private IRepository<User> _userRepo = null;
// UserRepositoryService injected through DI here
public Application(IRespository<User> userRepo) { _userRepo = userRepo; }
...
public void CreateUser(String userId) {
User newUser = new User(userId); // Data Object Created
_userRepo.Insert(newUser);
} // Data Object falls out of scope here
}
This is a simple example, but hope that helps.
edited Nov 10 at 15:15
answered Nov 10 at 15:03
Ryan Pierce Williams
43719
43719
Thanks for the answer still trying to wrap my head around DI so maybe first I need to understand some even more basic concepts before I try to understand the answer to this question. ( I came to the conclusion that this is on the "next level". I am missing the basics. )
– jhegedus
Nov 19 at 5:14
1
@jhegedus The best remedy for that is to go through some example DI applications and get some experience writing your own. I think it takes everyone a while to grasp ioc, since it flips everything on its head.
– Ryan Pierce Williams
Nov 19 at 20:04
add a comment |
Thanks for the answer still trying to wrap my head around DI so maybe first I need to understand some even more basic concepts before I try to understand the answer to this question. ( I came to the conclusion that this is on the "next level". I am missing the basics. )
– jhegedus
Nov 19 at 5:14
1
@jhegedus The best remedy for that is to go through some example DI applications and get some experience writing your own. I think it takes everyone a while to grasp ioc, since it flips everything on its head.
– Ryan Pierce Williams
Nov 19 at 20:04
Thanks for the answer still trying to wrap my head around DI so maybe first I need to understand some even more basic concepts before I try to understand the answer to this question. ( I came to the conclusion that this is on the "next level". I am missing the basics. )
– jhegedus
Nov 19 at 5:14
Thanks for the answer still trying to wrap my head around DI so maybe first I need to understand some even more basic concepts before I try to understand the answer to this question. ( I came to the conclusion that this is on the "next level". I am missing the basics. )
– jhegedus
Nov 19 at 5:14
1
1
@jhegedus The best remedy for that is to go through some example DI applications and get some experience writing your own. I think it takes everyone a while to grasp ioc, since it flips everything on its head.
– Ryan Pierce Williams
Nov 19 at 20:04
@jhegedus The best remedy for that is to go through some example DI applications and get some experience writing your own. I think it takes everyone a while to grasp ioc, since it flips everything on its head.
– Ryan Pierce Williams
Nov 19 at 20:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232000%2fwhat-is-it-meant-by-local-vs-global-objects-in-this-article-about-dependency-inj%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown